请帮助: 调试时我收到此错误 ' DataGrid1中'没有宣布。由于其保护级别,它可能无法访问。 vb.net
整个代码如下:
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Create ADO.NET objects.
Private myConn As SqlConnection
Private myCmd As SqlCommand
Private myReader As SqlDataReader
Private results As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Create a Connection object.
myConn = New SqlConnection("Initial Catalog=dbo.DispatchedBranches;User ID=Guestdmin2;Password=KL9791/*" &
"Data Source=LP2012-HP\SQLEXPRESS;Integrated Security=SSPI;")
'Create a Command object.
myCmd = myConn.CreateCommand
myCmd.CommandText = "SELECT FirstName, LastName FROM DispatchedBranches"
'Open the connection.
myConn.Open()
myReader = myCmd.ExecuteReader()
'Concatenate the query result into a string.
Do While myReader.Read()
results = results & myReader.GetString(0) & vbTab &
myReader.GetString(1) & vbLf
Loop
'Display results.
MsgBox(results)
'Insert a line of code before the DataReader and Connection objects are closed in the Form1_Load event procedure.
'The end of the procedure should appear as follows
SqlDataAdapter1.Fill(DataSet1, "DispatchedBranches")
myReader.Close()
myConn.Close()
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
DataGrid1.SetDataBinding(DataSet1, "DispatchedBranches")
End Sub
End Class