Can i assign datagrid.datasource = datareaderwill it work?will it fill my datagrid with the valuesthankx in advance.parikshit sehgal

Showing Answers 1 - 14 of 14 Answers

Dim dTable AS new DataTable Dim qry AS String = "SELECT ItemNo, ItemName, ItemDescription FROM tblItem" Dim sqlCommand AS new SqlCommand(qry, sqlConn) sqlConn.Open ResultGrid.DataSource = sqlCommand.ExecuteReader() ResultGrid.DataBind() sqlConn.Close

  Was this answer useful?  Yes

sivakesh

  • Nov 28th, 2005
 

no... You Cant... you can assig only dataSet or dataDable...

  Was this answer useful?  Yes

Mrityunjayan

  • Dec 14th, 2005
 

Sivakesh is absolutely wrong. u can very well provide data reader as datasource. only thing is that u cannot do sorting and paging(paging can be done , but with difficulty)

We can bind datagrid to datareader.Sorting and paging also possible since we can able to sort the grid itself with out need of dataset or dataview.The only disadvantage is that it overcome the disconnected dataset concept when we using datareader.

  Was this answer useful?  Yes

bala_siva1979@yahoo.co.in

  • Feb 17th, 2006
 

Dim connString As String = "Server=localhost;Database=Northwind;Integrated Security=SSPI"
Dim sql As String = "SELECT * FROM Products"

Dim conn As SqlConnection = New SqlConnection(connString)
Dim command As SqlCommand = New SqlCommand(sql, conn)

Try
conn.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
Me.DataGrid1.DataSource = reader
Me.DataGrid1.DataBind()
Catch ex As Exception
' Exception handling code goes here
Finally
conn.Close()
End Try

deb

  • Mar 10th, 2006
 

 

i dont think paging is possible by using datareader in datagrid........

 

we can bind data to datagrid using datareader in web application(asp.net) only ...........in windows application it is not possible...

regards

deb

  Was this answer useful?  Yes

SasiKarasi

  • Jan 19th, 2008
 

Yes You can assign DataReader as datasource to DataGrid. But datareader is read only so, you can't modify the data.

Correct me if I am wrong.
-----------------------------------
Life is too short and so sweet.
(sasi . karasi @ gmail . com)

  Was this answer useful?  Yes

please try this ,

//first create the columns to be displayed in the datagridview
MySqlConnection objcon = new MySqlConnection(Give u r database conection here);

objcon.Open();

MySqlCommand objcmd = new MySqlCommand();

objcmd.Connection = objcon;

objcmd.CommandText =
"select * from abc";

MySqlDataReader reader= objcmd.ExecuteReader();

while (reader.Read())

{



dataGridView1.Rows.Add(reader.GetString(
"ColumnName").ToString());

}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions