点击查询就执行一个SQL语句,为啥有错?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChaxun.Click
' Set the SelectCommand properties...
myDataAdapter.SelectCommand = New SqlCommand()
myDataAdapter.SelectCommand.Connection = myConnection
myDataAdapter.SelectCommand.CommandText = _
"SELECT au_lname, au_fname, title, price " & _
"FROM authors " & _
"JOIN titleauthor ON authors.au_id = titleauthor.au_id " & _
"JOIN titles ON titleauthor.title_id = titles.title_id " & _
"ORDER BY au_lname, au_fname"
myDataAdapter.SelectCommand.CommandType = CommandType.Text
' Open the database connection...
myConnection.Open()
' Now execute the command...
myDataAdapter.SelectCommand.ExecuteNonQuery()
' Fill the DataSet object with data...
myDataAdapter.Fill(myDataSet, "authors")
' Close the database connection...
myConnection.Close()
' Set the DataGrid properties to bind it to our data...
grdAuthorTitles.DataSource = myDataSet
grdAuthorTitles.DataMember = "authors"
' Declare objects for the DataGrid...
Dim objDataGridTableStyle As New DataGridTableStyle()
Dim objTextCol As New DataGridTextBoxColumn()
' Set the AlternatingBackColor property...
objDataGridTableStyle.AlternatingBackColor = Color.WhiteSmoke
' Set the MappingName for the DataGridTableStyle...
objDataGridTableStyle.MappingName = "authors"
' Set the MappingName for the first column...
objTextCol.MappingName = "au_lname"
' Set the new HeaderText...
objTextCol.HeaderText = "Last Name"
' Add the column to the DataGridTableStyle...
objDataGridTableStyle.GridColumnStyles.Add(objTextCol)
' Get a new reference to the DataGridTextBoxColumn...
objTextCol = New DataGridTextBoxColumn()
' Set the MappingName for the second column...
objTextCol.MappingName = "au_fname"
' Set the new HeaderText...
objTextCol.HeaderText = "First Name"
' Add the column to the DataGridTableStyle...
objDataGridTableStyle.GridColumnStyles.Add(objTextCol)
' Get a new reference to the DataGridTextBoxColumn...
objTextCol = New DataGridTextBoxColumn()
' Set the MappingName for the third column...
objTextCol.MappingName = "title"
' Set the new HeaderText...
objTextCol.HeaderText = "Book Title"
' Set the Width of the column...
objTextCol.Width = 304
' Add the column to the DataGridTableStyle...
objDataGridTableStyle.GridColumnStyles.Add(objTextCol)
' Get a new reference to the DataGridTextBoxColumn...
objTextCol = New DataGridTextBoxColumn()
' Set the MappingName for the fourth column...
objTextCol.MappingName = "price"
' Set the new HeaderText...
objTextCol.HeaderText = "Retail Price"
' Set the Alignment within the column...
objTextCol.Alignment = HorizontalAlignment.Right
' Add the column to the DataGridTableStyle...
objDataGridTableStyle.GridColumnStyles.Add(objTextCol)
' Add the DataGridTableStyle to the DataGrid...
grdAuthorTitles.TableStyles.Add(objDataGridTableStyle)
End Sub