需要关于此错误的帮助,无法找出出错的地方..
`导入System.Windows.Forms 导入System.Data.Sql 导入System.Data.SqlClient 导入System.Configuration
Public Class Celclass
Dim conn As SqlConnection
Dim cmd, cmd1, cmd2, cmd3 As SqlCommand
Dim da, da1, da2, da3 As SqlDataAdapter
Dim ds, ds1, ds2, ds3 As DataSet
Dim dt, dt1, dt2, dt3 As DataTable
Dim dr, dr1, dr2, dr3 As DataRow
Dim scb, scb1, scb2, scb3 As SqlCommandBuilder
Public Sub conn1(ByVal sql As String, ByVal dsname As String)
conn = New SqlConnection()
conn.ConnectionString = ConfigurationManager.AppSettings("ConnectionString")
cmd = New SqlCommand(sql, conn)
da = New SqlDataAdapter
da.SelectCommand = cmd
ds = New DataSet
da.Fill(ds, dsname)
End Sub
Public Sub conn2(ByVal sql As String, ByVal dsname As String)
conn = New SqlConnection()
conn.ConnectionString = ConfigurationManager.AppSettings("ConnectionString")
cmd1 = New SqlCommand(sql, conn)
da1 = New SqlDataAdapter
da1.SelectCommand = cmd1
ds1 = New DataSet
da1.Fill(ds1, dsname)
End Sub
Public Sub conn3(ByVal sql As String, ByVal dsname As String)
conn = New SqlConnection()
conn.ConnectionString = ConfigurationManager.AppSettings("ConnectionString")
cmd2 = New SqlCommand(sql, conn)
da2 = New SqlDataAdapter
da2.SelectCommand = cmd2
ds2 = New DataSet
da2.Fill(ds2, dsname)
End Sub
Public Sub conn4(ByVal sql As String, ByVal dsname As String)
conn = New SqlConnection()
conn.ConnectionString = ConfigurationManager.AppSettings("ConnectionString")
cmd3 = New SqlCommand(sql, conn)
da3 = New SqlDataAdapter
da3.SelectCommand = cmd3
ds3 = New DataSet
da3.Fill(ds3, dsname)
End Sub
Public Sub clear()
txtPart.ReadOnly = True
txtMpn.ReadOnly = True
txtdc.ReadOnly = True
txtQty.ReadOnly = True
txtPO.ReadOnly = True
cmbCoo.SelectedIndex = -1
cmbCoo.Text = ""
txtPart.Text = ""
txtMpn.Text = ""
txtBatch.Text = ""
txtdc.Text = ""
txtQty.Text = ""
txtPO.Text = ""
chk.Checked = False
End Sub
Private Sub txtJob_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtJob.TextChanged
txtJob.Text = Trim(txtJob.Text)
conn1("select p.qty, p.lot, p.mpn, p.dc1, p.dc2, p.dc3, s.raw, s.so_raw, s.prog, s.po, p.job_no from prod_pt p inner join pln_so s on p.so_id=s.so_id where p.job_no='" & txtJob.Text & "'", "pt")
If ds.Tables("pt").Rows.Count > 0 Then
dr = ds.Tables("pt").Rows(0)
If dr("po") = "" Then
MsgBox("No PO Key in!")
txtJob.Text = ""
Exit Sub
End If
Dim fulldc As String = ""
fulldc = fulldc + dr("dc1")
If UCase(dr("dc2")) <> "NA" And dr("dc2") <> "" Then
fulldc = fulldc + "/" + dr("dc2")
End If
If UCase(dr("dc3")) <> "NA" And dr("dc3") <> "" Then
fulldc = fulldc + "/" + dr("dc3")
End If
txtJob.Text = UCase(dr("job_no"))
If dr("prog").Equals(System.DBNull.Value) = False Then
If dr("prog") <> "" Then
txtPart.Text = UCase(dr("prog"))
Else
txtPart.Text = UCase(dr("so_raw"))
End If
Else
txtPart.Text = UCase(dr("so_raw"))
End If
txtMpn.Text = UCase(dr("mpn"))
txtdc.Text = fulldc
txtQty.Text = dr("qty")
txtPO.Text = UCase(dr("po"))
txtBatch.Focus()
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Dim m As Form
m = Main
Me.Close()
m.Show()
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
txtPart.ReadOnly = False
txtMpn.ReadOnly = False
txtdc.ReadOnly = False
txtQty.ReadOnly = False
txtPO.ReadOnly = False
End Sub
Public Sub insert(ByVal qty As String)
Dim x As Integer
Dim coo As String
If chk.Checked = True Then
x = 2
Else
x = 1
End If
If cmbCoo.Text = "GERMANY" Then
coo = "DE"
ElseIf cmbCoo.Text = "JAPAN" Then
coo = "JP"
ElseIf cmbCoo.Text = "MALAYSIA" Then
coo = "MY"
ElseIf cmbCoo.Text = "PAPUA NEW GUINEA" Then
coo = "PG"
ElseIf cmbCoo.Text = "SINGAPORE" Then
coo = "SG"
ElseIf cmbCoo.Text = "UNITED STATES" Then
coo = "US"
Else
coo = cmbCoo.Text
End If
For i As Integer = 1 To x
conn4("select * from label_celclass", "insert")
dt3 = ds3.Tables("insert")
dr3 = dt3.NewRow
dr3("part") = txtPart.Text
dr3("mpn") = txtMpn.Text
dr3("batch") = txtBatch.Text
dr3("dc") = txtdc.Text
dr3("qty") = qty
dr3("po") = txtPO.Text
dr3("coo") = coo
dt3.Rows.Add(dr3)
scb3 = New SqlCommandBuilder(da3)
da3.InsertCommand = scb3.GetInsertCommand
da3.Update(ds3, "insert")
ds3.AcceptChanges()
Next
End Sub
Public Sub delete()
Dim con As SqlConnection = New SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))
Dim str As String = "DELETE FROM label_celclass"
Dim cmd As SqlCommand = New SqlCommand(str, con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub
Public Sub printing()
conn1("select * from label_celclass", "others")
Dim retval
retval = Shell(Config.BarTenderFile & " /F=C:\barcode\cele.btw /P /X", vbMinimizedFocus)
'telford
'retval = Shell("C:\Program Files\Seagull\BarTender 6.20\Enterprise\bartend.exe /F=C:\barcode\cele.btw /P /X", vbMinimizedFocus)
'cele
'retval = Shell("C:\Program Files\Seagull\BarTender\7.75\bartend.exe /F=C:\barcode\cele.btw /P /X", vbMinimizedFocus)
'jabil
'retval = Shell("C:\Program Files\Seagull\BarTender\8.00\bartend.exe /F=C:\barcode\cele.btw /P /X", vbMinimizedFocus)
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
If txtBatch.Text = "" Then
MsgBox("Please key in Batch No")
txtBatch.Focus()
Exit Sub
End If
If cmbCoo.Text = "" Then
MsgBox("Please select COO")
cmbCoo.Focus()
Exit Sub
End If
Dim qty, part, reel As Integer
delete()
conn1("select * from production_oqc where job_no='" & txtJob.Text & "' and status='Accept'", "oqc")
If ds.Tables("oqc").Rows.Count > 0 Then 'oqc record found
For i As Integer = 0 To ds.Tables("oqc").Rows.Count - 1
dr = ds.Tables("oqc").Rows(i)
qty = dr("qty_per_reel")
insert(CStr(qty))
Next
Else 'no oqc record found
conn2("select s.fa_ref_no, s.revision, s.pkg, s.lead from pln_so s inner join prod_pt p on s.so_id=p.so_id where p.job_no='" & txtJob.Text & "'", "fa")
dr1 = ds1.Tables("fa").Rows(0)
If dr1("fa_ref_no") <> "" Then 'get from fa taping
conn3("select * from fa_taping where fa_ref_no='" & dr1("fa_ref_no") & "' and revision='" & dr1("revision") & "'", "taping")
If ds2.Tables("taping").Rows.Count > 0 Then 'fa taping record found
dr2 = ds2.Tables("taping").Rows(0)
qty = dr2("qty_per_reel")
If CInt(txtQty.Text) > qty Then 'more than 1 reel
part = CInt(txtQty.Text) Mod qty
reel = (CInt(txtQty.Text) - part) / qty
For j As Integer = 0 To reel - 1
insert(CStr(qty))
Next
If part <> 0 Then
insert(CStr(part))
End If
Else
insert(txtQty.Text)
End If
Else 'no fa taping record found, use fa taping mast
conn4("select * from fa_taping_mast where pkg='" & dr1("pkg") & "' and lead='" & dr1("lead") & "' and status='Approved'", "mast")
If ds3.Tables("mast").Rows.Count > 0 Then 'fa taping mast record found
dr3 = ds3.Tables("mast").Rows(0)
qty = dr3("qty_per_reel")
If CInt(txtQty.Text) > qty Then 'more than 1 reel
part = CInt(txtQty.Text) Mod qty
reel = (CInt(txtQty.Text) - part) / qty
For k As Integer = 0 To reel - 1
insert(CStr(qty))
Next
If part <> 0 Then
insert(CStr(part))
End If
Else
insert(txtQty.Text)
End If
Else 'no fa taping mast record found
insert(txtQty.Text)
End If
End If
Else 'get from fa taping mast
conn3("select * from fa_taping_mast where pkg='" & dr1("pkg") & "' and lead='" & dr1("lead") & "' and status='Approved'", "taping_mast")
If ds2.Tables("taping_mast").Rows.Count > 0 Then 'fa taping mast record found
dr2 = ds2.Tables("taping_mast").Rows(0)
qty = dr2("qty_per_reel")
If CInt(txtQty.Text) > qty Then 'more than 1 reel
part = CInt(txtQty.Text) Mod qty
reel = (CInt(txtQty.Text) - part) / qty
For l As Integer = 0 To reel - 1
insert(CStr(qty))
Next
If part <> 0 Then
insert(CStr(part))
End If
Else '1 reel
insert(txtQty.Text)
End If
Else 'no fa taping mast record found
insert(txtQty.Text)
End If
End If
End If
printing()
clear()
txtJob.Text = ""
txtJob.Focus()
End Sub
Private Sub btnPaper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaper.Click
Dim p As Form
p = Celclass_papertaping
Me.Close()
p.Show()
End Sub
结束班
上的错误
Private Sub txtJob_TextChanged(ByVal sender As System.Object,ByVal e As System.EventArgs)处理txtJob.TextChanged conn1(“select p.qty,p.lot,p.mpn,p.dc1,p.dc2,p.dc3,s.raw,s.so_raw,s.prog,s.po,p.job_no from prod_pt p在p.so_id = s.so_id上的内连接pln_so s其中p.job_no ='“&amp; txtJob.Text&amp;”'',“pt”)
答案 0 :(得分:0)
简化到最简单的级别,您获得的是StackOverflowException
,因为您在自己的txtJob.Text
事件处理程序中更改了TextChanged
。所以最终发生的是:
txtJob
。txtJob.TextChanged
事件。txtJob_TextChanged
事件处理程序。txtJob_TextChanged
内,您的代码会更改txtJob.Text
。txtJob.TextChanged
事件。解决方法是添加一个Boolean
标志,指示代码仍在处理文本更改:
Private _istxtJobProcessing As Boolean
Private Sub txtJob_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtJob.TextChanged
'If we're already processing, bail out now.
If _istxtJobProcessing Then Return
'Set a flag so that we know that we are already processing.
_istxtjobProcessing = True
' Now run your code here...
' And afterward, reset the flag.
_istxtJobProcessing = False
End Sub
您还应该知道您编写的SQL代码容易受到SQL injection的攻击。如果您搜索该主题,您将在VB.NET中找到有关如何通过参数化查询来避免此问题的大量答案。