将数据从oledb数据库获取到VB.Net中的数据网格视图

时间:2013-03-07 12:53:54

标签: sql vb.net

尝试从数据库中提取数据并将其显示在数据网格视图的表中。 正在创建带有标题的表,但它不会填充值。 一些代码被注释掉,因为我试图首先使用2个表。 非常感谢任何帮助,基本的视觉基础知识!

Public Class DriverOption

Public Sub btnStaff_Click(sender As System.Object, e As System.EventArgs) Handles btnStaff.Click

    Dim objconnection As New OleDb.OleDbConnection("Provider=msdaora;Data Source=orabis;User Id=112221800;Password=112221800;")

    Dim objinvoicesDA As New OleDb.OleDbDataAdapter("select * from CUSORDER, CUSORDER ", objconnection)

    Dim objinvoicesCB As New OleDb.OleDbCommandBuilder(objinvoicesDA)

    Dim objdataset As New DataSet()


    Dim objordersdA As New OleDb.OleDbDataAdapter("select CUSORDER.ORDERID, CUSORDER.ORDERDATE, CUSORDER.STAFFID, CUSTOMER.CUSTOMERID,  CUSTOMER.CUSTOMERADD_1 FROM CUSORDER,CUSTOMER WHERE CUSORDER.CUSTOMERID = CUSTOMER.CUSTOMERID", objconnection)  'orderdetails.unitprice from orders , orderdetails where orders.orderid = orderdetails.orderid", objconnection)

    Dim objordersCB As New OleDb.OleDbCommandBuilder(objordersdA)

    'Dim objcustomersDA As New OleDb.OleDbDataAdapter("select * from CUSTOMER", objconnection)

    'Dim objcustomersCB As New OleDb.OleDbCommandBuilder(objcustomersDA)


    'Dim objproductsDA As New OleDb.OleDbDataAdapter("select * from Products", objconnection)

    'Dim objproductsCB As New OleDb.OleDbCommandBuilder(objproductsDA)


    'Public Sub retrieve()
    'objdataset.Clear()

    'objproductsDA.FillSchema(objdataset, SchemaType.Source, "Products")


    'objproductsDA.Fill(objdataset, "Products")


    'objcustomersDA.FillSchema(objdataset, SchemaType.Source, "CUSTOMER")


    'objcustomersDA.Fill(objdataset, "CUSTOMER")
    objordersdA.FillSchema(objdataset, SchemaType.Source, "CUSTOMER")


    objordersdA.Fill(objdataset, "CUSTOMER")

    objordersdA.FillSchema(objdataset, SchemaType.Source, "CUSORDER")


    objordersdA.Fill(objdataset, "CUSORDER")


    'objinvoicesDA.FillSchema(objdataset, SchemaType.Source, "invoices")


    'objinvoicesDA.Fill(objdataset, "invoices")


    ViewDeliverys.DataGridView1.DataSource = objdataset.Tables("CUSORDER")

1 个答案:

答案 0 :(得分:0)

有任何错误吗?你有没有尝试调试代码,看看你是否填充了数据集,问题出在哪里?
我不明白这个查询Dim objinvoicesDA ...(“select * from CUSORDER,CUSORDER”,objconnection):这个“CUSORDER,CUSORDER”这种类型的查询存在吗?