-1

我有一个关于加入两个表和 1 个数据集并传递给 datgridview 的错误。我是菜鸟。我的流程是我想在两个表中显示选定的列并在单个 datagridview 行中显示.. 我的查询在 sql server management studio 中运行,但是当我在 vb.net 中对其进行编码时,它会导致错误.. 请帮助我..

这是我在 sql server management studio 中的代码:

Select a.CeramicLotNo,a.CeramicPartsNo, b.CerlotNo,b.MoldingLot
            from tblHikLotMgtDB as a
            INNER JOIN tblHikConchart as b
            On a.CeramicLotNo = b.CerlotNo
            where b.CerLotNO = 'W13D004-015'

那么这是我在 vb.net 中的代码

 Private Sub btnHiSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHiSearch.Click
        cerlot = Trim(txtHiSearch.Text)
        dgrid.Rows.Clear()

    Dim con As SqlConnection = New SqlConnection("Server=ITS-CODER02\DIBMART; Initial Catalog = HiKLotMgt; User Id= sa; Password = !@#;")
    con.Open()


    sql = "Select a.CeramicLotNo,a.CeramicPartsNo, b.CerlotNo,b.MoldingLot" & _
       "from tblHikLotMgtDB as a" & _
       "INNER JOIN tblHikConChart as b" & _
       "On a.CeramicLotNo = b.CerlotNo" & _
       "where a.CeramicLotNo = '" & cerlot & "'"
    Dim da As New SqlDataAdapter(sql, con)
    Dim ds As New DataSet

    da.Fill(ds, "tblHikLotMgtDB")
    da.Fill(ds, "tblHikConChart")

    ds.Tables("tblHikLotMgtDB").TableName = "tblHikLotMgtDB"
    ds.Tables("tblHikConChart").TableName = "tblHikConChart"
    dgrid.Rows.Add(ds.Tables("tblHikLotMgtDB").Columns("CeramicPartsNo"), ds.Tables("tblHiKLotMgtDB").Columns("CeramicLotNo"), ds.Tables("tblHikConChart").Columns("MoldingLot"), ds.Tables("tblHikConChart").Columns("CerLotNo"))
    con.Close()
End Sub

谢谢..

4

1 回答 1

0

您的查询的行部分之间缺少空格:

"Select a.CeramicLotNo,a.CeramicPartsNo, b.CerlotNo,b.MoldingLot" & _
   "from tblHikLotMgtDB as a" & _
    ^

在每行的末尾或下一行的开头添加一个空格。或将每一行与vbCrLf

于 2013-08-28T02:00:11.620 回答