我在vb.net中工作,从SQL访问数据时遇到无效列名问题
我使用MSSQL作为后端。
我提到了许多链接,谷歌搜索但无法解决我的问题
我遇到问题的代码是:
Private Sub txtAccCode_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtAccCode.TextChanged
Try
mQry = " from FAMPAR where Account_Code = '" & txtAccCode.Text & "'"
If Not CheckEof("select *" & mQry, con1) Then
txtAccName.Text = GetData("select Party_Name " & mQry, con1)
txtProPart.Text = GetData("select Proprietor" & mQry, con1)
txtRef.Text = GetData("select Reference_By" & mQry, con1)
txtAdd1.Text = GetData("select Address_1" & mQry, con1)
txtAdd2.Text = GetData("select Address_2" & mQry, con1)
txtCity.Text = GetData("select City" & mQry, con1)
txtPhno.Text = GetData("select Phone_No" & mQry, con1)
txtEmail.Text = GetData("select Email" & mQry, con1)
txtDrugLic.Text = GetData("select Drug_License" & mQry, con1)
txtGst.Text = GetData("select GST_No" & mQry, con1)
txtCst.Text = GetData("select CST_No" & mQry, con1)
txtCustBank.Text = GetData("select Customer_Bank" & mQry, con1)
txtAreaCode.Text = GetData("select Area_Code" & mQry, con1)
txtCustGrpCode.Text = GetData("select Cust_GrpCode" & mQry, con1)
txtDisc.Text = GetData("select Disc_Perc" & mQry, con1)
txtOpeningBal.Text = GetData("select Open_Bal" & mQry, con1)
txtCurrBal.Text = GetData("select Curr_Bal" & mQry, con1)
txtCcd.Text = GetData("select CC_DD" & mQry, con1)
txtStopDays.Text = GetData("select Stop_Days" & mQry, con1)
txtBillOutstdg.Text = GetData("select Fix_Days" & mQry, con1)
txtRemarks.Text = GetData("select Description" & mQry, con1)
cmbRetTax.Text = GetData("select Retail_Taxable" & mQry, con1)
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
我在上面的代码中使用的GetData函数是
Function GetData(qry As String, Xcn As SqlConnection)
Try
da = New SqlDataAdapter(qry, Xcn)
dt = New DataTable
da.Fill(dt)
GetData = IIf(Trim(dt.Rows(0).Item(0)) <> "", Trim(dt.Rows(0).Item(0)), "")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
现在问题是它在textAreaCode.text之前是正确的,但是从textCustGrpCode.text错误开始说&#34;无效的列名(列的名称)&#34;。错误屏幕截图显示在下面的链接中..
另一件事是当我用txtCustGrpCode.text行或其下面的任何其他行扭曲txtAreaCode.text行位置时,textAreaCode.text将错误标记为&#34;无效的列名(列名)&#34;而另一条线正常工作。
Plz告诉我我错在哪里...
任何帮助都将被接受..!
答案 0 :(得分:1)
为什么不使用数据适配器和数据表将选定的列数据放到文本框中会很容易。
strQuery = " SELECT * FROM DIVISION ORDER BY DIVISIONCODE"
Dim DataAdapeter As New SqlDataAdapter(strQuery, myConnection)
Dim dsDivision As New DataSet
myConnection.Open()
DataAdapeter.Fill(dsDivision)
DtDivision = dsDivision.Tables("DIVISION")
myConnection.Close()
DrDivision = DtDivision.Rows(i)
textbox1.text = DrDivision("DIVISION").ToString
textbox2.text = DrDivision("DIVISIONCODE").ToString
此代码可能有助于您了解如何使用表适配器和数据表。
答案 1 :(得分:0)
添加说明字段[说明] ,因为这是 keywoard 。检查其他字段(如果有)