I had a data grid on the form and the DataSource was set in the properties window. I was able to query the table by creating a connection and SqlDataAdapter with a SQL string created on the fly. Everything worked fine.
I then refined the code so I could query other tables (SQL Server 2005). I cleared the DataSource property for the DataGrid from the proerties widnow. I can now query other tables, but I don't get scroll bars and I can't view any data that is outside of the visible part of the DataGrid. The RowCount property tells me it returned 3000 rows, but I can't scroll the datagrid to get to anything past the top 10 or so.
Here's is my code. Any help is appreciate.
I then refined the code so I could query other tables (SQL Server 2005). I cleared the DataSource property for the DataGrid from the proerties widnow. I can now query other tables, but I don't get scroll bars and I can't view any data that is outside of the visible part of the DataGrid. The RowCount property tells me it returned 3000 rows, but I can't scroll the datagrid to get to anything past the top 10 or so.
Here's is my code. Any help is appreciate.
VB.NET:
Private Sub RunSQLCode(ByVal sSQL As String)
If Len(sSQL) = 0 Then
Exit Sub
End If
Dim connection As New SqlConnection("Data Source=00.100.0.0\XXXXXX;Initial Catalog=XXXXXX;Persist Security Info=True;User ID=sa;Password=XXXXXXX")
Me.Cursor = Cursors.WaitCursor
connection.Open()
Dim adapter As New SqlDataAdapter(sSQL, connection)
Dim dataset As New DataSet '
Try
adapter.Fill(dataset)
Catch ex As Exception
Me.Cursor = Cursors.Default
adapter.Dispose()
connection.Close()
MsgBox(ex.ToString)
Exit Sub
End Try
adapter.Dispose()
connection.Close()
Dim table As DataTable = dataset.Tables(0)
DataGridView1.DataSource = table
lblSQLinfo.Text = DataGridView1.RowCount & " rows returned."
Me.Cursor = Cursors.Default
End Sub