i create few textboxes, if i enter data in txtItemCode, the rest txtbo
will display data that read from database. show below.
================================================== ======== Private Su
txtItemCode_KeyPress(ByVal sender As Object, ByVal e A
System.Windows.Forms.KeyPressEventArgs) Handles txtItemCode.KeyPress
Dim db As New OleDbCommand _
("SELECT * FROM [Item Master]" & "WHERE ItemCode ='"
txtItemCode.Text & "'", dc)
dc.Open()
dr = db.ExecuteReader
Dim total As Single
While dr.Read()
txtDescription.Text = dr.Item(2)
txtUnitPrice.Text = dr.Item(4)
Exit Sub
End While
dc.Close()
End Sub
================================================== ========
then i got a btnOk to enter all the data into listview.
================================================== ========
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e A
System.EventArgs) Handles btnOk.Click
If txtItemCode.Text = "" Then
MessageBox.Show("Please fill in Item Code!", "Sale"
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtItemCode.Focus()
Exit Sub
End If
Try
Dim strSQL As String
strSQL = "INSERT INTO SaleByItem " & _
"(ItemCode, Description,Qty,UnitPrice,Total)VALUE
" & _
"('" & txtItemCode.Text & "'," & _
"'" & txtDescription.Text & "','"
NumericUpDown1.Text & "', " & _
"'" & txtUnitPrice.Text & "','" & txtTotal.Text
"')"
dc.Open()
Dim cmd As New OleDbCommand(strSQL, dc)
cmd.ExecuteNonQuery()
Call listview()
dc.Close()
Exit Sub
Catch
MessageBox.Show("Error occured when trying to save data!",
"Sale", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtItemCode.Focus()
Exit Sub
End Try
txtItemCode.Focus()
txtItemCode.Clear()
txtDescription.Clear()
NumericUpDown1.Text = 1
txtUnitPrice.Clear()
txtTotal.Clear()
End Sub
================================================== ========
but when i first click on btnOk, the msgbox in blue color font abov
prompt out,if i click second time on the btnOK , then it work. th
third time i click on btnOk,the error msg prompt out and state that m
CONNECTION STATE IS ALREADY OPEN. and highlighted the code whic
occured erro(YELLOW COLOR) and immediately close my program. the cod
in red color are cant work also, but i remember the first time i try
dont have this kind of error.can someone pls tell me where im wrong? :
--
le
-----------------------------------------------------------------------
lea's Profile:
http://www.msusenet.com/member.php?userid=156
View this thread:
http://www.msusenet.com/t-187051032