问题描述
我有SQL数据库,有以下表格详细信息;
账单没有特定价格单位金额税务税额
2905空运100.000 100 10000.000 0.000 0.000
2905海关4500.00 1 0.000 4500.000 675.000
2906 THC 250.000 1 0.000 250.000 38.000
2906 XYZ 5000.00 1 5000.000 0.0000 0.0000
在窗口形式中,我有一个名为Tbblbillto.Text的文本框,用于搜索bill no和Datagrid,其名称如下。什么时候我会打字在文本框中,如何将所有数据从sql数据库数据表中收集到账单no并在datagrid中显示?请帮助如何完成这项工作。实际上,我正在为自己的工作而工作,从不经历任何软件或学习。
特定价格单位金额税务税
我尝试过:
I have SQL DataBase with following tables details;
Bill No Particular Price Unit Amount Taxamount Tax
2905 Airfreight 100.000 100 10000.000 0.000 0.000
2905 Customs 4500.00 1 0.000 4500.000 675.000
2906 THC 250.000 1 0.000 250.000 38.000
2906 XYZ 5000.00 1 5000.000 0.0000 0.0000
In window form i have a textbox named as Tbblbillto.Text to search bill no and Datagrid with following name. when i will type bill no. in textbox, how all the data can collect from sql database data table against the bill no and display in the datagrid ?? Please help how can get this done. actually i am miking it for my own work and never experience any software or studied.
Particular Price Unit Amount Taxamount Tax
What I have tried:
Private Sub Tbblbillto_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tbblbillto.TextChanged
Dim Cmd As New SqlClient.SqlCommand
Dim Con As New SqlClient.SqlConnection
Dim Rd As SqlDataReader
Con.ConnectionString = "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=dbase;Integrated Security=True;Pooling=False"
Cmd.Connection = Con
Con.Open()
Cmd.CommandText = "Select * from Bill where BillNo = '" & Tbblbillto.Text & "'"
Rd = Cmd.ExecuteReader
Rd.Read()
If Rd.HasRows Then
Dtpblbilldate.Text = Rd.Item("BillDate")
Dudblmode.Text = Rd.Item("Smode")
Dudbltype.Text = Rd.Item("Stype")
Lbcur.Text = Rd.Item("Curency")
Tbbljobno.Text = Rd.Item("JOBNo")
Dtpbljobdt.Text = Rd.Item("JobDate")
Tbbillexr.Text = Rd.Item("ExRate")
Tbblcrdit.Text = Rd.Item("CreditPeriod")
Lbbillno.Text = Rd.Item("BillNoType")
Tbbillcltid.Text = Rd.Item("ClientID")
Tbblname.Text = Rd.Item("BillTo")
Tbblmawb.Text = Rd.Item("MAWBBLNo")
Dtblmawbdt.Text = Rd.Item("MAWBBLDate")
Tbblhawb.Text = Rd.Item("HAWBBLNo")
Dtblhawbdt.Text = Rd.Item("HAWBBLDate")
Tbblorg.Text = Rd.Item("Origin")
Tbblpol.Text = Rd.Item("POL")
Tbbldst.Text = Rd.Item("Dest")
Tbblpod.Text = Rd.Item("POD")
Tbblpro.Text = Rd.Item("Products")
Tbblinv.Text = Rd.Item("ShInvNo")
Dtblinvdt.Text = Rd.Item("ShInvdt")
Tbblqty.Text = Rd.Item("Qty")
Tbblgwt.Text = Rd.Item("Gwt")
Tbblcwt.Text = Rd.Item("Cwt")
Tbblacof.Text = Rd.Item("Acof")
Tbblcarrier.Text = Rd.Item("Carrier")
Dudblfreight.Text = Rd.Item("Freight")
Dudblterms.Text = Rd.Item("Incotrm")
Cmd.CommandText = "Select BillNo from BillDetails Where BillNo = '" & Tbblbillto.Text & "'"
Rd.Close()
Rd = Cmd.ExecuteReader
Rd.Read()
If Rd.HasRows Then
Dim Row As DataGridViewRow
Dim I As Integer
For I = 0 To Dgvbillsa.Rows.Count - 1
Row = Dgvbillsa.Rows(I)
Using SqlCommand As New SqlCommand
Row.Cells(0).Value = Rd.Item("Particular") (Error Here)
Row.Cells(1).Value = Rd.Item("Price")
Row.Cells(2).Value = Rd.Item("Unit")
Row.Cells(3).Value = Rd.Item("Amount")
Row.Cells(4).Value = Rd.Item("TaxAmount")
Row.Cells(5).Value = Rd.Item("Tax")
End Using
Next
End If
ElseIf Len(Tbblbillto.Text) > 3 Then
MsgBox("No Invoice Record Found", MsgBoxStyle.Critical, "MODIFY BILL")
CmdEdit.Enabled = False
End If
End Sub
推荐答案
Dim Int As Integer
Row = Dgvbillsa.Rows(Int) (Here is Error)
您应该尝试设置使用之前 int
的值。
You should try to set the value of int
before using it.
Cmd.CommandText = "Select * from BillDetails Where BillNo = '" & Tbblbillto.Text & "'"
你有另一个问题。
永远不要通过连接用户输入来构建SQL查询,它被命名为SQL注入,它对你的数据库很危险并且容易出错。
名称中的单引号和程序崩溃。如果像Brian O'Conner这样的用户输入可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞。
[]
[]
这篇关于索引超出范围异常 - {" specific"}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!