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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid error 1

Status
Not open for further replies.

jeffmoore

Programmer
Aug 29, 2003
301
US
Just trying to get data into a datagrid but it doesn't like my second to last line

Dim oSQLConn As SqlConnection = New SqlConnection
oSQLConn.ConnectionString = "Initial Catalog=rathmisc;User Id=sysadm;Password=sysadm;"
Dim MyDataAdaptor As System.Data.sqlclient.SqlDataAdapter
Dim MyDataTable As New DataTable
MyDataAdaptor = New SqlDataAdapter("select * from tbl_data_laser_1", oSQLConn)
MyDataAdaptor.Fill(MyDataTable)
DataGrid1.DataSource = MyDataTable

Code halts at the second to last line....

tia
jeff
 
You might need to fill a dataset as opposed to a DataTable.

Give that a try.
 
just tried that ... same error :

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
 
I used this code to get it to work.

Dim oSQLConn As New System.Data.SqlClient.SqlConnection
oSQLConn.ConnectionString = "[Connection Info]"
Dim MyDataAdaptor As New System.Data.sqlclient.SqlDataAdapter("select * from
", oSQLConn)
Dim DataSet As New DataTable
MyDataAdaptor.Fill(DataSet)
DataGrid1.DataSource = DataSet

I did however get the error you are getting when my select statement was not correct, so take you select statement and run that against the database directly to validate it is correct.
 
okay I'm getting further.... now I get this!!!!

error: Complex DataBinding accepts as a data source either an IList or an IListSource
 
woo hooo ..... this works!!!!


Dim connect As New SqlConnection("initial catalog=rathmisc;data source=server;user id=sysadm;password=sysadm")
Dim MyDataAdaptor As New System.Data.sqlclient.SqlDataAdapter("select * from tbl_data_laser_1", connect)
Try
connect.Open()
Dim DataSet As New DataTable
MyDataAdaptor.Fill(DataSet)
DataGrid1.DataSource = DataSet

Catch Ex As Exception
Console.WriteLine("error: " & Ex.Message)
End Try

connect.Close()



Thanks.... alll
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top