T
Tony M
VS 2005 - vb .net - windows xp pro - windows app
All I'm trying to do for now is populate a datagridveiw (dgvTest).
I trying to learn how to retrieve records from DB and add, edit, delete.
I know there are records in the DB b/c I'm able to display records using the
control itself.
Now I want to do it dynamically. I'm really trying to retrieve records from
DB and manipulate them and update them. After I get this to run I want to
use a datareader and learn how that works.
dgvTest is empty when I run this code. I don't know how to bind the data or
if that is even the problem. The code runs w/o error.
Dim SqlCon As SqlConnection
Dim SQL As String
Dim SqlCmd As New SqlCommand
Dim SqlAdpt As New SqlDataAdapter
Dim SqlDS As New DataSet
SqlCon = New SqlConnection("Server=.\SQLExpress;AttachDbFilename=C:\Program
Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\MyFirstDatabase.mdf;
Database=dbname;Trusted_Connection=Yes;")
Try
SQL = "Select * from TonysTable2"
SqlAdpt = New SqlDataAdapter(SQL, SqlCon)
SqlAdpt.SelectCommand.Connection.Open()
SqlAdpt.Fill(SqlDS, "TonysTable2")
dgvTest.DataSource = SqlDS.DefaultViewManager
SqlCon.Close()
SqlCon = Nothing
MsgBox("Whoo hooo connected")
Catch ex As Exception
If SqlCon.State Then
SqlCon.Close()
SqlCon = Nothing
End If
MsgBox(ex.ToString)
End Try
End Sub
Thanks
All I'm trying to do for now is populate a datagridveiw (dgvTest).
I trying to learn how to retrieve records from DB and add, edit, delete.
I know there are records in the DB b/c I'm able to display records using the
control itself.
Now I want to do it dynamically. I'm really trying to retrieve records from
DB and manipulate them and update them. After I get this to run I want to
use a datareader and learn how that works.
dgvTest is empty when I run this code. I don't know how to bind the data or
if that is even the problem. The code runs w/o error.
Dim SqlCon As SqlConnection
Dim SQL As String
Dim SqlCmd As New SqlCommand
Dim SqlAdpt As New SqlDataAdapter
Dim SqlDS As New DataSet
SqlCon = New SqlConnection("Server=.\SQLExpress;AttachDbFilename=C:\Program
Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\MyFirstDatabase.mdf;
Database=dbname;Trusted_Connection=Yes;")
Try
SQL = "Select * from TonysTable2"
SqlAdpt = New SqlDataAdapter(SQL, SqlCon)
SqlAdpt.SelectCommand.Connection.Open()
SqlAdpt.Fill(SqlDS, "TonysTable2")
dgvTest.DataSource = SqlDS.DefaultViewManager
SqlCon.Close()
SqlCon = Nothing
MsgBox("Whoo hooo connected")
Catch ex As Exception
If SqlCon.State Then
SqlCon.Close()
SqlCon = Nothing
End If
MsgBox(ex.ToString)
End Try
End Sub
Thanks