adspace
I want to fetch data from datareader. i have three tables in
datareader. i want to bind my two table with datagrid, then
i want to fetch a value from my third table. do u have any
idea pls help me. we use dr.nextresult() for multiple tables.
Answer Posted / Sunidhi Pandey
To achieve this in .NET Framework, you can use the SqlDataReader and DataSet classes. You should first fill your two tables into the DataTable of DataSet and bind them to the DataGridView. To fetch data from the third table, move the reader to the appropriate result set by calling dr.NextResult(). Here's a basic example:nn```csharpnusing System; using System.Data.SqlClient; // ...nstring connectionString = "your connection string"; SqlConnection con = new SqlConnection(connectionString); con.Open(); SqlCommand cmd = new SqlCommand("your query", con); SqlDataReader reader = cmd.ExecuteReader(); DataSet ds = new DataSet(); if (reader.HasRows) {n // Fill first two tables heren}n reader.NextResult(); // Move to the third table's result setn // Get and use the desired valuen reader.Close(); con.Close();```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers