Getting the number of Rows (Records)

How do I get and return the number of rows (records) in a sql 2005 database, Some code samples would be helpful

Thanks

Joe

 

0
bigjoe11a
7/19/2008 4:01:20 AM
asp.net.getting-started 91979 articles. 3 followers. Follow

8 Replies
417 Views

Similar Articles

[PageSpeed] 33

Hi,

that would be something like this:

select count(*) from yourTable

The * can also be replaced by a columnname but since I didn't know your table structure I used * in the example.

Grz, Kris.


Read my blog. Handy Firefox plugins for web developers.


Workaround for non working Mark as answer buttons.
0
XIII
7/19/2008 7:28:49 AM

Ok, guys this isn't going to work. Take a look at my code. I need it to return the current record that was inserted. Is there a was to do that

 

 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim Members As MembershipUser = Membership.GetUser()
        Dim UserNameID As Guid = Members.ProviderUserKey

        Dim Album As New SqlDataSource()
        Album.ConnectionString = ConfigurationManager.ConnectionStrings("UserDataDB").ToString()
        Album.InsertCommandType = SqlDataSourceCommandType.Text
        Album.InsertCommand = "INSERT Into Albums (AlbumName, Publicok, UserID, UserName, CreateDate) Values (@AlbumName, @Publicok, @UserID, @UserName, @CreateDate)"
        Album.InsertParameters.Add("AlbumName", TextBox1.Text)
        Album.InsertParameters.Add("Publicok", CheckBox1.Checked)
        Album.InsertParameters.Add("UserID", UserNameID.ToString())
        Album.InsertParameters.Add("UserName", User.Identity.Name)
        Album.InsertParameters.Add("CreateDate", Date.Now().ToString())

        Try
            Album.Insert() 'Insert new Album
            CheckDir("~/Photo/Album" + countrows().ToString())  'Creates a Album Directory base on the AlbumID
            Album.Dispose()
            Server.Transfer("AddAlbum.aspx")

        Catch ex As Exception
            Label1.Text = "Error occured." & Err.Description
        End Try
    End Sub

 So how could I get the current AlbumID

Thanks

Joe

 

 

0
bigjoe11a
7/20/2008 4:33:48 PM

OK, first that's an entirely different question. Second I don't see an identity field for your album records. Third, yes you can get an ID for the last record inserted, but only if you create a table with an ID field to retrieve. Finally, another option is to simply assign the GUID before inserting.


Don't believe everything you think

Sarasota Web Design
0
JZoerman
7/20/2008 5:05:47 PM

JZoerman:

OK, first that's an entirely different question

Thats what I thought

Second I don't see an identity field for your album records.

Never had to put in in before

Third, yes you can get an ID for the last record inserted, but only if you create a table with an ID field to retrieve. Finally,

Ok, How

 

 another option is to simply assign the GUID before inserting.

 

What ? I have used GUID before. related to the UsersID

0
bigjoe11a
7/20/2008 8:26:25 PM

 Thanks Kris, its just that is way over my head. I have to think of some thing else

 

0
bigjoe11a
7/20/2008 9:41:14 PM

Second I don't see an identity field for your album records.

Sorry Joe, had a little brain fart there Stick out tongue, you don't if table is setup to create newid(). Anyway, @@Identity, Scope_Identity is an option like Kris mentioned.

Another option, instead of automatically creating new GUID's on insert, simpy use System.Guid.NewGuid() and assign the ID yourself.

JZ


Don't believe everything you think

Sarasota Web Design
0
JZoerman
7/20/2008 11:43:55 PM

 Don't worry about it. I scape the that part of my project any way

JZoerman:

Second I don't see an identity field for your album records.

Sorry Joe, had a little brain fart there Stick out tongue, you don't if table is setup to create newid(). Anyway, @@Identity, Scope_Identity is an option like Kris mentioned.

Another option, instead of automatically creating new GUID's on insert, simpy use System.Guid.NewGuid() and assign the ID yourself.

JZ

 
0
bigjoe11a
7/21/2008 12:50:56 AM
Reply:

Similar Artilces:

How to set the row number and get the row number for ("selected row) in Datagrid
I face a problem that i can't get the selected row of the datagrid in both server side script (VB.net) and client side script (javascript) As i can't use the button column / hyperlink column in the datagrid. Thus , i need to handle the change the background color of the selected row and also to get the selected row number for Update/Delete. Thanks in advance. This depends on how do you perform the selection. Do you want to implement chaning of the SelectedRow at the client side without any postback? If you have no issues with postback, then you can do s little trick here: 1. ...

POST GET GET GET GET... WTH?
Hi, I'm at a loss to explain this... I have an ASPX page that I can't always navigate to. When I developed the app (it's Starter Kit Portal-based), I did it on my LAN and have had no trouble accessing the page. However, upon deployment, I see the following behavior: 1. POST request goes out looking for MyForm.aspx 2. GET request for MyForm.aspx 3. GET request for MyForm.aspx 4. ... X. GET request Sometimes, the page finally loads. Other times, it just ends up blank. Many times, it doesn't load at ALL the first POST - I just get a "The pa...

Getting number of rows/records in PB6
Hi! Can anyone tell me how I calculate out how many rows/records there are in a database? I have a datawindow with the all database records listed but i would like to find out how many rows there actually are. And preferably from the window using script so i can store that number in a variable for later use. I know i can use the "computed object" in the datawindow (count function...) but the thing is that i need the value of total rows(or total number of records in the database if you will) stored in a global variable. I know several ways of doing this in VB, but can&...

Get the Row Number or Row ID
Hi, I am using Sybase Central v4.3 with Interactive SQL to query the SQL Commands. My concern is how to get the rownumber or row id in select queries. Is there any in built commands in the ASE. If not please suggest me how to get the rownumber. Thanks.... Unless i'm mistaken, ASE does not use a rowid... it can have a timestamp, but it is updated with every modification to the row. http://infocenter.sybase.com/help/topic/com.sybase.help.ase_15.0.blocks/html/blocks/blocks34.htm -- Cory Sane [TeamSybase] Certified Sybase Associate DBA for ASE 15.0 "Santhanam P" wrote...

trying to get started and i am getting this error
when i go to http://www.porkchopsplayground.com, i get: DotNetNuke Upgrade Error The Assembly Version ( [ASSEMBLYVERSION] ) does not match the Database Version ( [DATABASEVERSION] ) ERROR: Could not connect to database. Could not find file 'd:\hosting\nmoran26\Providers\DataProviders\AccessDataProvider\DotNetNuke.mdb'. Any suggestions will be appreciated. Thanks, Nicole Do you have a username and password set on your database? Make sure you follow the steps mentionned in the Readme.txt located in the documentation folder. In any case make sure your credentials for yo...

how to get start with .NET
the net help people installed  to my desktop 1-microsoft visual studio .NET enterprise developer 2003 2-microsoft .NET framework 1.1 what else do i need ...???  and how can i try with some simple code in VS.Net and run it to see wat happen...????? please help If you want to develope web applications, then you'll also need IIS on your PC.  That'll require XP-Professional or Windows 2000/2003, but XP-Home edition won't allow IIS installation. As for how to get started, you can search the web for some tutorials or buy a good book on VS.  The topic is way too vast to...

How do I get the row number?
I have tryed to find a way to include the row number in a querry but without result. I have a table select some rows ordered and now I will add a column called rank How do I get the rownumber in the field rank ? Thanks in advance Jan O Jan O www.olsmar.com The way I'd suggest assigning a row number to your resultset is to INSERT your resultset into a temporary table or table variable which has an IDENTITY column, something like this: -- set up a table variable to hold the resultset DECLARE @myTable (Rank int identity(1,1) primary_key, ColumnA va...

How to get the number of records?
Hi all, I would like to query the number of records with some condition. May I know how to get the number of records? My code is as follow: try { string connection = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=" + HostName + ";" + "DATABASE=" + Database + ";" + "UID=" + UID + ";" + "PASSWORD=password;" + "OPTION=3"; string strSelect = "select count(*) from EqpInfo where Server = '"+DropDownList1.SelectedValue+"'"; OdbcConnection conn = new OdbcConnection(connection); OdbcCommand cmd = new OdbcCommand(strSelect); cmd.Connection = conn; // Open connection conn.Open(); int N...

getting the number of rows...
how can you get the number of rows in query resault with out filling dataset and checking the "count"? afaik - you can't - - you've got to have an entity to count the rows - the dataset is the 'finished product' that contains the result of your query - until you've queried and received the data from the database, you don't know how many rows you've receivedDavid WierMCP/ASPInsiderASPNet101.com - where to look first!Control Grouper - easily control properties for multiple controls with one control!Calendar Express - The Best HTML Calendar Generator on the web!(Please 'Mark as ...

Getting Start With .net
hi i'm intersted to learn asp.net (vb or delphi) . i programming with delphi6 but i'd like to tp know something about programming in internet specially with .net . i hear about microsoft.net with delphi 7 that i can programming with delphi in .net .... is it right ? what 's our opinian about it ? and better to learn Vb.Net or continu with delphi(or delphi.net) thanks. Ali Darabian I think there is some support for Delphi in .Net. However, you will find much more support from the user community if you choose a more popular language such as VB.Net or C#. Since your al...

How do you get the number of rows
I have a gridview and I want to display the total number of rows of data like 5000 rows? This is not the same as the GridView1.Rows.Count, which gives the number of rows being displayed like 10 of 5000 rows. How do I get at the total? Hi, i think what you are asking is how to get the number of rows of the bounded dataset. Lets say you bound a dataset to the grid, you only need to get the number of rows of the first table in the dataset: myDataset.tables(0).rows.count As simple as that!   regards, njs That works in ASP.NET 1.x That doesn't work in ASP.NET 2.0...

get number from row
if i have a this string to select a row from database of acess: select TOP 1 * from odkazy how i elicit from it id column? i need know id from select row then just get the id... select top 1 id from odkazy... PS..you would need an order by clause in the select statement otherwise the TOP has no meaning.. hth***********************Dinakar NethiLife is short. Enjoy it.*********************** my problem: (for example) if i have 5 columns with numbers in select row and i want display cast of this numbers I write: one = ds.tables("Odkazy").Rows(i)("...

Getting line number to show during editing, getting values to show during debug, getting MSDN help to know that I have it installed
G'day, Sorry I feel so dumb but these issues just push me over the edge. I've recently had to re-install VS and now none of these features that I once had now don't work.  I obviously have to tweak something but what?  It doesn't seem too obvious (I hope!)Help please!Thanks,Geoff Line numbers - that can found under Tools > Options > Text Editor > (Language) > (somewhere there, there is is a check box for line numbers) When you are in the debug mode of the IDE, go into the Debug > Windows > (whatever windows you need - locals/autos are what you're l...

getting started in VS2005 C# which book should I get
Hello, I am getting started with VS2005, I have use VS2003 but not very much -(I did 4 small applications in it),  I am wondering which book you would recommend to learn the new features of VS2005, while learning more of C# programing in general There some links to good books in this thread i posted : http://forums.asp.net/thread/1489422.aspx Also these two make good reference material  Professional Visual Studio 2005 (Programmer to Programmer)   Microsoft Visual Studio 2005 Unleashed  So far I recommend Wrox's C# 2005  Read the beginning chap...

Web resources about - Getting the number of Rows (Records) - asp.net.getting-started

Embassies in Beijing Warn of Possible Threats Against Foreigners
Several foreign embassies in Beijing, including the American and British ones, warned on Thursday of possible threats against Westerners in a ...

‘He’s Number One in the Polls!’: CNN’s Cuomo Defends Trump Coverage to a Combative Sanders
During an interview on CNN this morning, Bernie Sanders complained about how much free airtime the media devotes to Donald Trump , while Chris ...

Who Is Sarco Plank And Was He In ‘Star Wars: The Force Awakens’?
Earlier we wrote about Constable Zuvio , a character that was featured in a lot of the early Star Wars: The Force Awakens marketing but didn’t ...

Kent: Car smashes through Costa Coffee shop window leaving 1 dead and 5 injured in Westerham
Audi smashed through the side of the coffee shop and was embedded in the building.

Migrants found guilty in brutal killing of British backpackers
New York Post Migrants found guilty in brutal killing of British backpackers New York Post Hannah Witheridge, left, and David Miller, the ...

Draftkings to ask Illinois court to rule on legality of fantasy sports
(Reuters) - Fantasy sports company DraftKings will ask a court to decide the question of whether it can offer daily fantasy sports games in Illinois, ...

Hyatt hotels reveal malware discovered in payment systems
Following a series of hotel chains that have recently disclosed the presence of malware in their payment processing systems, Hyatt has come forward ...

Lunch Lady Fired for Good Deed Offered Job Back
An Idaho lunch lady who said she was fired for giving a free meal to a student in need is now being offered her job back, according to the school ...

Planned Parenthood shooter wants to act as own lawyer
Washington Post Planned Parenthood shooter wants to act as own lawyer Charlotte Observer El Paso County District Attorney Dan May, center, ...

Reasons British Muslim Family Was Barred From US Entry, Disneyland: Facebook Page Linked To Taliban ...
Mohammad Tariq Mahmood made headlines when he claimed that his British Muslim family was barred from entry into the United States “because he ...

Resources last updated: 12/24/2015 8:11:37 PM