我想在datagirdview中包含两行的数据,使用我的列已显示的代码,但是数据,我的意思是该行中没有数据。 这是我的代码
Dim sqlcon As New SqlConnection("Data Source=ALLAYE\SQLEXPRESS;Initial Catalog=Business;Integrated Security=True")
Dim sqlcmd As New SqlCommand("SELECT OrderTB.OrderID, OrderTB.CustomerID, OrderTB.OrderDate, OrderTB.TotalOrder, CustomerTB.CustomerID AS CusID, CustomerTB.CompanyName, CustomerTB.CustomerPhone
FROM OrderTB INNER JOIN
CustomerTB ON OrderTB.CustomerID = CustomerTB.CustomerID", sqlcon)
sqlcon.Open()
Dim sqladp As New SqlDataAdapter(sqlcmd)
Dim dt As New DataTable
sqladp.Fill(dt)
DataGridView1.DataSource = dt.TableName
sqlcon.Close()
答案 0 :(得分:-1)
尝试一下。
Imports System.Data.SqlClient
Public Class Form1
Dim connetionString As String
Dim connection As SqlConnection
Dim adapter As SqlDataAdapter
Dim cmdBuilder As SqlCommandBuilder
Dim ds As New DataSet
Dim changes As DataSet
Dim sql As String
Dim i As Int32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
connection = New SqlConnection(connetionString)
Sql = "select * from Product"
Try
connection.Open()
adapter = New SqlDataAdapter(Sql, connection)
adapter.Fill(ds)
connection.Close()
DataGridView1.Data Source= ds.Tables(0)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class