Insert DATAREADER into DATAGRID control
Hello All,
I want to insert a dataReader object into DataGrid object . the code looks like this
conn = new SQLiteConnection(Form1.connectionString);
string query = "SELECT * FROM patient";
SQLiteCommand cmd = new SQLiteCommand(query,conn);
conn.Open();
SQLiteDataReader dataReader = cmd.ExecuteReader();
datagrid.DataSource = dataReader;
I want to display all the dataReader content through dataGrid object.
Please can ayone tell me whether this is possible? if possible how should i do that?
******** IMPORTANT THING IS IT IS NOT AN ASP.NET APPLICATION
Please help .
Thanks and Regards
Pavan joshi
[681 byte] By [
pavanjosh] at [2007-11-20 0:45:19]

# 1 Re: Insert DATAREADER into DATAGRID control
code u are trying is for asp.net datagrid, in vb.net it doesn't work
try this
'get datareader
Dim sSQL As String = "SELECT * FROM student"
Dim sConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\attendence.mdb;Persist Security Info=False"
Dim oCn As OleDbConnection = New OleDbConnection(sConnString)
Dim oSelCmd As OleDbCommand = New OleDbCommand(sSQL, oCn)
oSelCmd.CommandType = CommandType.Text
oCn.Open()
Dim oDr As OleDbDataReader = oSelCmd.ExecuteReader()
''Construct DataTable''
Dim dt As New DataTable
Dim i As Integer
Dim count As Integer = oDr.FieldCount - 1
'add columns
For i = 0 To count
dt.Columns.Add(oDr.GetName(i), oDr.GetFieldType(i))
Next
'add rows
Do While oDr.Read()
Dim r As DataRow = dt.NewRow
For i = 0 To count
r(i) = oDr.Item(i)
Next
dt.Rows.Add(r)
Loop
Me.DataGridView1.DataSource = dt