How to get data in column from dataset
-
How to get data in column from dataset? i have data in dataset and i want data from some column in dataset.
dataset.tables(0).row(0).column(0).item(0).tostring()
-
How to get data in column from dataset? i have data in dataset and i want data from some column in dataset.
Easy..
//lv_DtSet is dataset containing data.. if (lv_DtSet.Tables[0].Rows.Count > 0) { foreach (DataRow lv_Row in lv_DtSet.Tables[0].Rows) { if (!Convert.IsDBNull(lv_Row["ColumnName"])) String ColumnData = (String)lv_Row["ColumnName"]; //Alternately u can use Column index also. } }
"If our Mind can, the Program can !!" ≡ ░Ŗǿђầŋ٭ ≡
-
Easy..
//lv_DtSet is dataset containing data.. if (lv_DtSet.Tables[0].Rows.Count > 0) { foreach (DataRow lv_Row in lv_DtSet.Tables[0].Rows) { if (!Convert.IsDBNull(lv_Row["ColumnName"])) String ColumnData = (String)lv_Row["ColumnName"]; //Alternately u can use Column index also. } }
"If our Mind can, the Program can !!" ≡ ░Ŗǿђầŋ٭ ≡
What is the difference in using the column index and the column name? which one is advantageous? -- modified at 2:11 Monday 14th May, 2007
-
How to get data in column from dataset? i have data in dataset and i want data from some column in dataset.
-
What is the difference in using the column index and the column name? which one is advantageous? -- modified at 2:11 Monday 14th May, 2007
Both have their own importance. Lets consider an example Suppose you are getting data from Database using a Stored procedure. Stored procedure contains Select as..
Select ID, Name, Value from Table1
When you will use this DB procedure in the C#.. You have 2 options Either to get by Column name or by Index..long id; String Name, Value; // using Index id = (long) lv_DtSet.Tables[0].Rows[0][0]; Name = (String) lv_DtSet.Tables[0].Rows[0][1]; Value = (String) lv_DtSet.Tables[0].Rows[0][2]; //using Column Name id = (long) lv_DtSet.Tables[0].Rows[0]["ID"]; Name = (String) lv_DtSet.Tables[0].Rows[0]["Name"]; Value = (String) lv_DtSet.Tables[0].Rows[0]["Value"];
Now, if you look at Index case you don't know which value u r retrieving. So, if someday DB person changes sequence of columns say..Select ID, Value, Name from Table1
you r in trouble. B'coz no exception will be raised.. bt Name and Value will get interchanged. So I will prefer to use Column name in this case. B'coz Changing of column name in DB is less likely. And eventhough the Sequence of columns in Select query gets changed, u don't have to change your code. But there are some times.. u don't know column names OR u want to read data serially Column1, column2 etc.. then use Column indexes. Depends on situation. But I will prefer to use Column name as far as possible. And by the way its.. ROHAN :)
"If our Mind can, the Program can !!" ≡ ░Ŗổђầŋ٭ ≡
-
Both have their own importance. Lets consider an example Suppose you are getting data from Database using a Stored procedure. Stored procedure contains Select as..
Select ID, Name, Value from Table1
When you will use this DB procedure in the C#.. You have 2 options Either to get by Column name or by Index..long id; String Name, Value; // using Index id = (long) lv_DtSet.Tables[0].Rows[0][0]; Name = (String) lv_DtSet.Tables[0].Rows[0][1]; Value = (String) lv_DtSet.Tables[0].Rows[0][2]; //using Column Name id = (long) lv_DtSet.Tables[0].Rows[0]["ID"]; Name = (String) lv_DtSet.Tables[0].Rows[0]["Name"]; Value = (String) lv_DtSet.Tables[0].Rows[0]["Value"];
Now, if you look at Index case you don't know which value u r retrieving. So, if someday DB person changes sequence of columns say..Select ID, Value, Name from Table1
you r in trouble. B'coz no exception will be raised.. bt Name and Value will get interchanged. So I will prefer to use Column name in this case. B'coz Changing of column name in DB is less likely. And eventhough the Sequence of columns in Select query gets changed, u don't have to change your code. But there are some times.. u don't know column names OR u want to read data serially Column1, column2 etc.. then use Column indexes. Depends on situation. But I will prefer to use Column name as far as possible. And by the way its.. ROHAN :)
"If our Mind can, the Program can !!" ≡ ░Ŗổђầŋ٭ ≡
Is there any difference in the speed that who will get u the records quickly???????
-
Is there any difference in the speed that who will get u the records quickly???????
-
How to get data in column from dataset? i have data in dataset and i want data from some column in dataset.