473,320 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

to check if a datatable has only one row!

21
hi,

i hv a datatable. now there arises a need where i have to perform an action only if the datatable has only one row. Is there anyway i can check if my datatable has only one row?

thanks!
May 20 '07 #1
5 1698
kenobewan
4,871 Expert 4TB
When you create the datatable from a datareader you could also have a counter.
May 20 '07 #2
vanc
211 Expert 100+
if you are programming to check database, you can manually check tables rows
a. connect to database
b. query table rows and put in datareader
c. while(datareader.Read()) counter++;
d. counter's value is the table's rows.

cheers.
May 20 '07 #3
alan75
60
just use sql query:

select count(*) as rowctr from table

reader.read()

noOfRow = reader("rowctr")
May 21 '07 #4
harini
21
thanks a lot for ur replies...but one clarification here...i m not using a datareader...i hv created a dataable by code and binded it to a datagrid....

so when its my last row in the table that i delete i shud do some other activities like enabling some buttons, etc...so for that i wrote a stmt,

if(sltdProdTrayRowIndex == 0 && dtProdTray.Rows.Count == 1)...is this rite?

will dtProdTray.Rows.Count == 1 check if the datatable has only one row? but it dosent seem to work. pls gimme a soln not involving data reader...

thanks a lot!
May 21 '07 #5
Plater
7,872 Expert 4TB
You wish to know where there is only one row left in the datagrid?

myDataGridView.Rows.Count

or if you just want the DataTable:

myDataTable.Rows.Count


Pretty simple
May 21 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Eva | last post by:
Hi i am trying to insert a new row into one of my datatabels that i have in my dataset when a button is clicked. here is my code Dim ClientInsRow As DataRow = dtClient.NewRo ...
6
by: Mountain Bikn' Guy | last post by:
When one gets a row from a database (ie, a DataTable), the row contains a typed value in each column. How is this typically implemented behind scenes. I want to build this functionality myself. The...
4
by: Randy | last post by:
I have a DataTable in a DataGrid. If I click on the DataGrid, HitTestInfo in dataGrid1_MouseDown returns a Row and Column number. I can use the Row number to say: DataRow dr = dataTable.Rows;...
5
by: jurson | last post by:
Hello, I remove row from DataTable. It works ok, the row is removed from collection. It should be marked as 'detached'. Am I right? Then I try to retrieve 'detached' rows using the code shown...
3
by: Gene Hubert | last post by:
I'm using DataTable.ImportRow to move data from one datatable to another... Dim dt, dtTarget As DataTable Dim dr As DataRow dt = DirectCast(Me.DataSource, DataTable) dtTarget = dt.Clone...
6
by: Danny Ni | last post by:
Hi, If I want to programatically add rows to a DataTable, do I call AcceptChanges per row? Or do I call AcceptChanges after all rows added? TIA
10
by: D. Shane Fowlkes | last post by:
I have a function that is called in page_load and the purpose of this function is to look up basic data in a MSSQL table and return it in the form of a datatable. The page_load will read the data...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
19
by: Dave | last post by:
If Iwant to check if dataset1.SelectQuery1.column1 == System.DBNull.Value. How do I do this? What I wrote above will give an error. -- L. A. Jones
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.