|
INTERVIEW QUESTIONS
MICROSOFT
ADO.NET
DETAILS
Question: How do I read records from the data tables?
Answer: You can read the records from the data table using its Rows collection. With the Rows collection, you need to specify the row number and column name or number to access a particular field of the specified row. For example, if we have read the ‘Student’ table in our data table, we can access its individual fields as: C# Version DataTable dt = ds.Tables["student"]; string stId = dt.Rows[0]["StudentID"].ToString(); string stName = dt.Rows[0]["StudentName"].ToString(); string stDateOfBirth = dt.Rows[0][2].ToString(); VB.Net Version Dim dt As DataTable dt = ds.Tables("student") Dim stId As String stId = dt.Rows(0)("StudentID").ToString() Dim stName As String stName = dt.Rows(0)("StudentName").ToString() Dim stDateOfBirth As String stDateOfBirth = dt.Rows(0)(2).ToString() Here we have retrieved various fields of the first record of the student table read in the dataset. As you can see, we can either specify the column name in string format or we can specify the column number in integer format. Also note that the field value is returned in the form of Object, so we need to convert it to the string before using it. Similarly, you need to cast variables of other data types before using them.
C# Version
int stAge = int.Parse(dt.Rows(0)("Age").ToString());
VB.Net Version
Dim stage As Integer stAge = Integer.Parse(dt.Rows(0)("Age").ToString())
|
|
|
Category |
ADO.NET Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 6965 users |
Added on |
8/31/2014 |
Views |
69574 |
Rate it! |
|
|
Question:
How do I read records from the data tables?
Answer:
You can read the records from the data table using its Rows collection. With the Rows collection, you need to specify the row number and column name or number to access a particular field of the specified row. For example, if we have read the ‘Student’ table in our data table, we can access its individual fields as: C# Version DataTable dt = ds.Tables["student"]; string stId = dt.Rows[0]["StudentID"].ToString(); string stName = dt.Rows[0]["StudentName"].ToString(); string stDateOfBirth = dt.Rows[0][2].ToString(); VB.Net Version Dim dt As DataTable dt = ds.Tables("student") Dim stId As String stId = dt.Rows(0)("StudentID").ToString() Dim stName As String stName = dt.Rows(0)("StudentName").ToString() Dim stDateOfBirth As String stDateOfBirth = dt.Rows(0)(2).ToString() Here we have retrieved various fields of the first record of the student table read in the dataset. As you can see, we can either specify the column name in string format or we can specify the column number in integer format. Also note that the field value is returned in the form of Object, so we need to convert it to the string before using it. Similarly, you need to cast variables of other data types before using them.
C# Version
int stAge = int.Parse(dt.Rows(0)("Age").ToString());
VB.Net Version
Dim stage As Integer stAge = Integer.Parse(dt.Rows(0)("Age").ToString()) Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How do I define a data adapter?
|
View Answer
|
|
How do I create a command and supply the SQL query to ADO.Net? (Command object and command string)
|
View Answer
|
|
How do I find the connection string for the database server?
|
View Answer
|
|
What are the basic steps involved in data access with ADO.Net in disconnected environment?
|
View Answer
|
|
What is the Dot Net Framework data provider for OLEDB?
|
View Answer
|
|
What is the Dot Net Framework data provider for Oracle?
|
View Answer
|
|
What is the Dot Net Framework data provider for SQL Server?
|
View Answer
|
|
Why should one use a specialized data provider when the data can be accessed with general data providers?
|
View Answer
|
|
What are the standard dot net framework data providers that are shipped with the Dot Net Framework 1.1?
|
View Answer
|
|
What does it mean by Dot Net Framework Data Provider?
|
View Answer
|
|
How do different components of ADO.Net interact with each other in disconnected architecture?
|
View Answer
|
|
What is a data reader?
|
View Answer
|
|
What is a database command?
|
View Answer
|
|
What is a database connection?
|
View Answer
|
|
What is a data adapter?
|
View Answer
|
|
What is a dataset?
|
View Answer
|
|
What are the different components of ADO.Net?
|
View Answer
|
|
How XML is supported in ADO.Net?
|
View Answer
|
|
How to select data set or data reader?
|
View Answer
|
|
What are the performance considerations when using dataset?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All ADO.NET Interview Questions & Answers - Exam Mode /
Learning Mode
|