导入 System.Data.OleDb
公开课形式1
这是我的连接字符串
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|datadirectory|STORE.accdb")
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
con.Open()
Dim cmd As New OleDbCommand("SELECT [QTY OTHER], [HQTY PL3], [HQTY PL5], [TOTAL QTY] FROM(MATERIAL)WHERE ([MAT CODE] = @a)", con)
cmd.Parameters.AddWithValue("@a", TextBox1.Text)
Dim dr As OleDbDataReader = cmd.ExecuteReader
Dim qtyotherm, hqtypl3m, hqtypl5m, totalqtym As New Double
Dim qtyotherr, rqtypl3r, rqtypl5r, qtyr As New Double
Dim totalqtyfinal As New Double
Dim cmdins As New OleDbCommand("INSERT INTO RECEPT ([MAT CODE], QTY, RATE, TAXES, [RQTY PL3], [RQTY PL5], [RQTY OTHER]) VALUES (@b, @c, @d, @e, @f, @g, @h)", con)
cmdins.Parameters.AddWithValue("@b", TextBox1.Text)
cmdins.Parameters.AddWithValue("@c", TextBox2.Text)
cmdins.Parameters.AddWithValue("@d", TextBox10.Text)
cmdins.Parameters.AddWithValue("@e", TextBox9.Text)
cmdins.Parameters.AddWithValue("@f", TextBox3.Text)
cmdins.Parameters.AddWithValue("@g", TextBox4.Text)
cmdins.Parameters.AddWithValue("@h", TextBox5.Text)
Dim checkinsert As New Integer
checkinsert = cmdins.ExecuteNonQuery
此执行非查询工作正常
If checkinsert > 0 Then
If dr.HasRows Then
While dr.Read
qtyotherm = dr(0)
hqtypl3m = dr(1)
hqtypl5m = dr(2)
totalqtym = dr(3)
End While
文本框显示加法值
totalqtyfinal = totalqtym + TextBox2.Text
TextBox15.Text = totalqtyfinal
MessageBox.Show("chk text box value")
问题从这里开始
Dim cmdupdate As New OleDbCommand("UPDATE MATERIAL SET [TOTAL QTY] = @j WHERE ([MAT CODE] = @i)", con)
cmdupdate.Parameters.AddWithValue("@i", TextBox1.Text)
cmdupdate.Parameters.AddWithValue("@j", TextBox15.Text)
Dim chkupdate As New Integer
chkupdate = cmdupdate.ExecuteNonQuery
If chkupdate > 0 Then
MessageBox.Show("update done :) ")
始终显示此其他声明消息
Else
MessageBox.Show("fail to update :(")
End If
MessageBox.Show("quer 1 and 2 is successfully executed")
Else
MessageBox.Show("dr not working.")
End If
Else
MessageBox.Show("insert query fail")
End If
con.Close()
End Sub
结束类