emaduddeen
Programmer
Hi Everyone,
Can you look at my code? Can you tell me why I can't display data in my data grid view?
The connection string comes directly from pasting the connection string from the server explorer and the SQL statement is from the query builder so I know those are ok.
Here's the code:
The code is from a tutorial that should be working, but I believe I left something out that is missing.
Thanks.
Truly,
Emad
Can you look at my code? Can you tell me why I can't display data in my data grid view?
The connection string comes directly from pasting the connection string from the server explorer and the SQL statement is from the query builder so I know those are ok.
Here's the code:
Code:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private strConnectString As String = "Data Source=.\SQLEXPRESS;" & _
"AttachDbFilename=D:\Development\VB\Emad\cbt1\DataSetExample\DataSetExample\Baseball.mdf;" & _
"Integrated Security=True;" & _
"User Instance=True"
Private objSqlConnection As New SqlConnection(strConnectString)
Private objSqlDataAdapter As New SqlDataAdapter
Private objDataSet As New DataSet
Private objSqlCommand As New SqlCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With objSqlCommand
.Connection = objSqlConnection
.CommandText = "SELECT Positions.Role, Players.PlayerName, Players.Rank, Players.HireDate, " & _
"Players.Sarary " & _
"FROM(Players) " & _
"INNER JOIN Positions ON Players.PositionCode = Positions.PositionID"
.CommandType = CommandType.Text
End With
objSqlDataAdapter.SelectCommand = objSqlCommand
objSqlConnection.Open()
objSqlDataAdapter.Fill(objDataSet, "Players")
objSqlConnection.Close()
' Show the data in the grid.
'---------------------------
With grdPlayers
.DataSource = objDataSet
.DataMember = "Players"
.AutoGenerateColumns = True
End With
objDataSet = Nothing
objSqlConnection = Nothing
objSqlCommand = Nothing
End Sub
End Class
The code is from a tutorial that should be working, but I believe I left something out that is missing.
Thanks.
Truly,
Emad