DataSource Controls :: Pull A Random Record From The Db?
Jan 22, 2010
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
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)
Dim dtt As New DataTable()
This is were I am stuck.
I need to filter all rows out except where row(index) = num
Me.GridView4.DataSource = dtt
Label1.Text = "Error: Unable to Pull 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 have location #s, date, time, the sales amount, and tax in a excel file. The system pulls sales numbers throughout the day from each store location and places the total sales and tax numbers along with the polling date into a file.
So the most current date/time has the most upto date sales numbers at the time for that location number, but it also lists the older entries so mgmt can see how sales went during the day, and this is where my issue is, I don't need to see the old numbers from this generated file (atleast at this part of the program).
What I would like to do is write a query that only selects the most recent sales numbers for each location. I will output this to a table in ASP.NET. The query I tried using the TOP 1 clause only gave me the very first row listed below.
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:-
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 was put in charge of a database that has no source control, and all work was done in the database. I want to pull all the objects (stored procs, views, tables) from the database, and add to my new source control.
Is there a way to get all the objects into individual files out of a database?
Our database is SQL 2005. I have Visual Studio 2005/2008/2010 (beta 2) at my disposal.
On a test page, I successfully created a google map that pulls both marker and infoWindow information from an XML file. I did this just to get a feel for working with the API. It works fine. However, I do have a SQL database that has this information in it already. This database is updated behind the scenes regulary via a webservice.
I would like to try pulling the map information from my SQL database instead so I don't have to hand maintain the .xml file. The dabase alread has the lat/long information needed for markers. What is the easiest way for me to get that data from the SQL database? Is there a way to run a query and use the data, or will I need to run the query and somehow have it write/update my .xml file for me?
I need to pull a SubString from a Linq Datasource, but can't use INTs per .SubString(int, int) I have strings such as xxxx.xxxx.xxxxx.AAAA.xxxx.xxxx.xxxx.xxx and I need to pull AAAA out. the preceeding x's will be varying lengths, so I can't use a static int. What I do know is that there will be a static number of periods (.) leading up to the AAAA. I can't figure out how to use the SubSting with characters rather than indexs. This is what I have so far:
I am creating an album using the following stored procedure, which returns the primary key for the newly created record:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[fpa_sp_albums_update_insert] @album_id int, @album_name nvarchar (50), @album_descr nvarchar(250), @album_img_cover_id_FK int, @album_creation_date date AS If @album_id > 0 UPDATE [fpa_albums] SET album_name=@album_name, album_descr= @album_descr, album_img_cover_id_FK = @album_img_cover_id_FK, album_creation_date = @album_creation_date Where ((album_id = @album_id)) Else INSERT INTO [fpa_albums] ( album_name, album_descr, album_img_cover_id_FK, album_creation_date) VALUES ( @album_name, @album_descr, @album_img_cover_id_FK, @album_creation_date) Return SCOPE_IDENTITY();
I execute the above stored procedure using the SQLHELPER. The VB.NET code for the page is as follows:
However, the createdAlbumID always shows -1 instead of the id for the newly created album.
How can I select a random row and then update or delete it? I've found how to get a random row, using SELECT TOP 1 column FROM table ORDER BY NEWID() do I have to make another select using this result in order to update the row, or it can be done more efficiently?
Is there any method by which we can retrieve random data from a dataset or rather directly from a table.
For example, I have around 30 questions in my table, I just wanted to display 20 among them and that too in a random order without the same item repeating. Can we achieve this using SP or through some Dataset manipulation?
For context: First of all, I am new to LINQ, as I have been using SubSonic for quite some time now.
I have two tables, Users, and Affiliates. They both have a very typical schema. The FK that joins them is the UserId field, which is in the Affiliates table. I want to create a LINQ query that pulls the Username from the Users table using the AffiliateId value. The AffiliateId is a primary key of the Affiliates table.
I have tried to accomplish this using many variations of the following code:
In the above query, I expect to get a single row result set. However, I instead receive the entire table of results.
How can I make this work? I have yet to see an example or article out there to do what I am trying to do.
I'm very new to this area and am using ASP.NET 3.5 with WMD 2008 Express Edition and VB code.
How do I write records to the SQL database using VB? I want to use the connection string, etc used in the ASP.NET controls if possible.
My website is a Rugby Club site and I've an SQL database of match fixtures which include TeamId(1XV, 2XV, etc.), Season(2008, 2009, etc) and match date.
I allow some users to update the fixture details but want to insert a series of new fixture records for the neext season which contain just TeamId Season and Match Dates. I therefore want to take the season and Team Id from label fields and then create match dates by adding seven days to a start date.
There are several articles and blogs that are sort of about this subject but I haven't found one on point. Wondering if anyone has done this? Using VS2008 creating an ASP.NET 3.5 app with a strongly-typed dataset connecting to an MS SQL backend. In one TableAdapter, I have a custom Insert statement that inserts the record into the primary table. There are two other tables the also need records inserted into them and those records contain the record ID from the primary table. Here's an example of what I'm trying to accomplish:
If I have an ID, I would like to retrieve the next item that also has the same category as the item ID I have. So, for example, if I have ID=2, I would like to return the item with ID=4 (as item ID=3 has a different category).
Just have a problem, I want people to join a mailing list, I just have a textbox and button. When a user enter's their email address, the address and time are inserted into a database. However, if the same email is added again I would like for a message to appear saying the record already exists.
Can someone show me how to do this, here is my current code: