ASP.NET - data set with rows count
Asked By hiren dhameliya on 13-Apr-10 07:24 AM
hi
how i can find total records in one tabal.
how i can compare particuratl tabel in rows of one sell
Sagar P replied to hiren dhameliya on 13-Apr-10 07:27 AM
You can get the total number of rows count in ds like this;
int rowsCnt = ds.Tables[0].Rows.Count;
You can also specify name of table like;
int rowsCnt = ds.Tables["Employee"].Rows.Count;
Web Star replied to hiren dhameliya on 13-Apr-10 07:31 AM
if u want to get row count in dataset use
int intCount;
intCount = ds.Tables["myTable"].Rows.Count;
but not clear about yr 2nd query what u wnat compare table rows of one sell?
Kirtan Patel replied to hiren dhameliya on 13-Apr-10 07:31 AM
you can count Rows By SQL Query too and Using the Count Property of Datable that is inside the Data Set
by SQL Query
select count(*) from table;
this will return you the row count in table
or
Using Data Table 's Count Property
int count = DataSet1.Tables[0].Rows.Count ;
Santhosh N replied to hiren dhameliya on 13-Apr-10 07:32 AM
you can compare any value inside the datatable by referencing them with the position inside the dataset as
Dataset
Datatable
Rows
Items (Column values)
you can compare like as...
Ds.Tables[0].Rows[0][0]
and
Ds.Tables[0].Rows[4][0]
Anoop S replied to hiren dhameliya on 13-Apr-10 07:51 AM
You can use self join for compare 2 rows of the same table
SELECT t1.value, t2.value
FROM MyTable t1, MyTable t2
WHERE t1.id = @id
AND t1.status = @status1
AND t2.id = t1.id
AND t2.status = @status2
you can use count function to count total number of records
eg
SELECT count( * ) as total_record FROM student
Mash B replied to hiren dhameliya on 13-Apr-10 09:11 AM
Suppose u have dataset names "mydataset" and table name of dataset as "table1" (even u can access table with index)
for comparing cells use below code
foreach (DataRow item in ds.Tables["table1"].Rows)
{
string temp = item["name"].ToString(); // "name" is column name
}
to get count of dataset use below code
ds.Tables["table1"].Rows.Count
Super Man replied to hiren dhameliya on 13-Apr-10 09:18 AM
SqlConnection
cn = new SqlConnection("your connection string");
SqlCommand
cmd = new SqlCommand("select count(*) from employee", cn);
int i =
cmd.ExecuteScalar();
Label1.Text = "there
are " + i.ToString() + " records in
employee table ";