SQL Server :: Show 5 Random Record From Table?
Jul 17, 2010i need to show for every refresh of page five categories, every time different how can i do? in SQL do not exist select RND(field)...
View 5 Repliesi need to show for every refresh of page five categories, every time different how can i do? in SQL do not exist select RND(field)...
View 5 RepliesHow to create sql server table with unique random identity between 45365 - 5782155129452 ?
View 5 Repliesi want show ten record from table in the gridview at 2 column in five row.
like this:
------------gridview-------------
record1 | record2
record3 | record4
record5 | record6
record7 | record8
record9 | record10
1 2 3 ...
-----------------------
[Code]....
The following table contains several records.Why do I see only the last stored data?
how to pull a RANDOM item from the database when using LINQ. There seems to be a couple of differnet ways to handle this. What I need to do though is pull a RANDOM item from the database that the user has not seen before.
The data I am pulling from the database is very small. Is there any way I can just hit the database once for 1000 records and then randomly scroll through those?
Should I put a cookie on the users system recording the IDs of which items they have seen, pull a random record, check to see if it is seen and if so, pull from the database again? That seems like performance issues just waiting to happen.
I want to pull a random record from the db.
Here what I have so far.
Dim RandomNumber As New Random()
Dim num As Integer
num = RandomNumber.Next(1, 75).ToString
Try
Dim Cnn As New OleDb.OleDbConnection("File Name=E:WebRHIUDLShelf_Life.UDL;")
Dim da As New OleDb.OleDbDataAdapter("SELECT tbMaster_List.dbMFG, tbMaster_List.dbDescription, tbInStock.ID, tbInStock.dbMFG_Lot_Code, tbInStock.dbDateReceived, tbInStock.dbDateOpened, tbInStock.dbExpireDate, tbInStock.dbLocation FROM (tbInStock
INNER JOIN tbMaster_List ON tbInStock.LnkToMaster = tbMaster_List.ID) ", Cnn)
Cnn.Open()
Dim dtt As New DataTable()
da.Fill(dtt)
This is were I am stuck.
I need to filter all rows out except where row(index) = num
Me.GridView4.DataSource = dtt
Me.GridView4.DataBind()
Catch
Label1.Text = "Error: Unable to Pull Data"
End Try
I'm trying to select a random record from my database and display the details of the record on screen. The table I am using is the aspnet_Users table which as I'm sure you all know holds the details of users. After a bit of googling, I found the following code:-
[Code]....
I've built my page and I get no errors which is a great start I just can't seem to figure out how to then display the results of this query on the page. I just want to display the username for the record that is selected.
I want to insert a new record into a table. The table has relationships with other secondary tables, For example:
Table: Stores
Table StoreCategories (a store can have many of these)
I want to insert a new store, get its ID and insert some categories in one go.
How do I go about this?
how to read last 20 record form a table for example (tb1) and the table consist of 3 column
View 4 RepliesI have a table that contain 1000 record and a webpage that contain 10 label to show the data in table and tow linkbutton for showing (next-previous) records. I want a query when i click on next show next 10 record and when i click on previous show previous 10 record (code in c# if possible)
View 3 RepliesI have one text box in my page and 1 button
users type some number in this TB
I want when users enter their number in text box and click on button to insert it to database
it checked if in database was that number it show message that "this number is in database please type other number"
how i can do it?
i made two table and their repectively sp
[code]....
nw firstly i insert all value which appears on Default.aspx page and then display on grid..
but primary i couldn't work insert that value then after display grid..
I'm using SQL Server 2005 in a project, and i need to duplicate a record from a table and all it's relationships.
View 9 RepliesIn oracle we can do this by using rowid.
select * from tableName where rowid = (select max(rowid) from tableName);
but i don't know equivalent of rowid in sql server.
I have a delete button bellow my gridview and I want a pop up to show when no record is selected and tell the user to first select a record. The button click event would show the pop up, but my gridview data blanks out.
Here is my code:
[Code]....
i need to call multi dropdown for products that retrieve product name from microsoft sql and get the price as the product is been selected from the dropdown for total amount for the customer.Example is for customer to buy 6 product.The client is to enter the number of product purchase and the 6 dropdown appears as he click ok button.And as the clients select the product from the dropdown the price sum up together before saving into database.
View 1 RepliesI have two tables with one common field. The field is the primary key in one table, and just a plain field in another. When I delete a record in the table where the common field is the primary key, I want to automaticaly delete a record in the other table that has the same data in the common field.
What is the most effecient method of doign this..triggers?
I'm working on an ASP.NET (C#) web project that is using master pages.
I'm looking for an easy way to display a random customer quote each time a page is loaded.
Since this is a fairly simple web project I'd like to stay away from storing the quotes in a database. Currently there is no database connections required for the project so I'd like to keep it as simple as possible -- perhaps storing the quotes in an XML file them using an XmlTextReader to read the file?
Edit: I will need to store and pull both a quote and a customer name for the quote.
I have a table where I have a column for different states (NY, NJ, etc). People can join the group (in my page) for each state (the state where they live). So I have to display the newest members for each state.
So the way it should work is, every time the page is refreshed/reloaded it should show the state name as a header text and the first 5 newest members for that state. This should be random, for example initially when the page is loaded say it will show state: New York and the 5 recent members like Stacy, Laura, Mike, Sam, Mathew.
Then when the page is refreshed it will show another state like State: california and the recent 5 members
I am counting from a table for that i have written code as below
protected void get_Id_Afterpoint()
{
int counter = 0;
string strSql = "select count(*) as ID from tblEnergy where ID=?";
OdbcCommand com = new OdbcCommand(strSql, con);
com.Parameters.AddWithValue("ID", DropDownList1.SelectedValue);
OdbcDataAdapter oda = new OdbcDataAdapter(com);
DataTable dt = new DataTable();
oda.Fill(dt);
if (dt.Rows.Count == 0)
{
lblID2.Text = "1";
}
else
{
counter = dt.Rows.Count;
counter = counter + 1;
lblID2.Text = Convert.ToString(counter);
}
}
there is no record related to DropDownList1.SelectedValue. but as i am counting if(dt.rows.count) and i put break point on the bolded part it shows 1 record. how it can be possible?
Why is this so hard? Seems like a simple task:
Here is what I am doing. Gridview to list a table. The table is mostly keys so I display one value and have a dropdown list to update the Instructor (key). Like one normally does, the dropdown list has a display value and a 'hidden' value which should be the value updated to the table, in the UPDATE event.
It does not work.
(1) When I click 'edit' the value in that field that was on the list of the grid is NOT the same value in the DropdownList, so the index of the ddl is not coming from the value on the grid (which is a hidden field on the grid).
(2) When I pick a new instructor, the value put into the table is basically random.
I would debug it but I have no idea what events to look at or how to look at the actions taking place during edit and update.
[Code]....
how can i select a record from A table and insert into B table using linq?
View 2 RepliesI am using Table Adapter to insert records into my database. I first insert my member record into the database and it has no errors, after that i insert the contact records into the table. however I got the following error: You cannot add or change a record because a related record is required in table 'Member'.
[Code]....
i am generate random password and show it in a textbox. when i am set textbox property textmode to password then it doesn't show in textbox but when i set it singleline then password shows in textbox. I am using following code --
textbox1.attributes.add("value",passwordvalue);
for show i am using --
textbox1.text = textbox1.attributes["value"].tostring();
Same happing with when i edit record. password doesn't show in textbox.
I create a table as picture below :
when I insert any character to column Name then A new string random will auto insert into column Random (picture below) I had used Trigger but It was error !
I want to column Random use to code :
DECLARE @myid uniqueidentifier
SET @myid = NEWID()
insert into table_1 values(@myid, substring(CONVERT(varchar(255), @myid), 1, 5))
but It must auto like column Number (column Number is Identity)