Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid and feeding data in it

Status
Not open for further replies.

tek1ket

MIS
Jan 25, 2009
70
IR
i have this code as following:
SqlConnection myConn= new SqlConnection(ConnInfo);
SqlCommand myComm=new SqlCommand("Select * from tblProject",myConn);
myConn.Open();
SqlDataReader dr= myComm.ExecuteReader();

if (dr.HasRows)
{
dgProject.DataSource=dr;
dgProject.Refresh();
}

dr.Close();
myComm.Dispose();
myConn.Close();
myConn.Dispose();

when i run the application ,it enteres the debug mode and a green line in dgProject.Refresh(); is appeared and also a window box which says
"an unhandled exception of type 'System.Exception' occured in System.windows.form.dll

Additional information: Complex DataBinding accepts as a data source either an IList or an IListSource"

where did i make a mistake?
 
i got my answer i should set the datasource of datagrid to datase or Array not datareader
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top