如何在Visual Studio中的表单上显示查询?

时间:2014-11-28 18:12:56

标签: sql vb.net

这是我到目前为止所拥有的。它应显示订单号,客户名称和订单总成本:

Private Sub OrdersQuery_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the '_Sweet_Lil_sDataSet.Orders' table. You can move, or remove it, as needed.
    Me.OrdersTableAdapter.Fill(Me._Sweet_Lil_sDataSet.Orders)

    Dim Connection = New OleDbConnection
    Connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=U:\Sweet Lil's.mdb"
    Connection.Open()

    Dim sql As String = "Select Orders.[Order ID], Orders.[Customer ID], Boxes.[Box Price], [Order Details].[Box ID], [Order Details].Quantity * Boxes.[Box Price] AS Expr1 " & _
        "((Orders INNER JOIN " & _
                "FROM        [Order Details] ON Orders.[Order ID] = [Order Details].[Order ID]) INNER JOIN " & _
                     "Boxes ON [Order Details].[Box ID] = Boxes.[Box ID]) " & _
    "ORDER BY Orders.[Order ID]"

    Dim da As New OleDbDataAdapter(sql, Connection)
    da.SelectCommand.CommandText = sql
    Dim ds As New DataTable
    da.Fill(ds)
    da.AcceptChangesDuringFill = False
    DataGridView1.DataSource = ds.DataSet()

    Connection.Close()
End Sub

0 个答案:

没有答案