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_Key Press(ByVal sender As Object, ByVal e A
System.Windows. Forms.KeyPressE ventArgs) Handles txtItemCode.Key Press
Dim db As New OleDbCommand _
("SELECT * FROM [Item Master]" & "WHERE ItemCode ='"
txtItemCode.Tex t & "'", dc)
dc.Open()
dr = db.ExecuteReade r
Dim total As Single
While dr.Read()
txtDescription. Text = dr.Item(2)
txtUnitPrice.Te xt = 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(ByV al sender As System.Object, ByVal e A
System.EventArg s) Handles btnOk.Click
If txtItemCode.Tex t = "" Then
MessageBox.Show ("Please fill in Item Code!", "Sale"
MessageBoxButto ns.OK, MessageBoxIcon. Exclamation)
txtItemCode.Foc us()
Exit Sub
End If
Try
Dim strSQL As String
strSQL = "INSERT INTO SaleByItem " & _
"(ItemCode, Description,Qty ,UnitPrice,Tota l)VALUE
" & _
"('" & txtItemCode.Tex t & "'," & _
"'" & txtDescription. Text & "','"
NumericUpDown1. Text & "', " & _
"'" & txtUnitPrice.Te xt & "','" & txtTotal.Text
"')"
dc.Open()
Dim cmd As New OleDbCommand(st rSQL, dc)
cmd.ExecuteNonQ uery()
Call listview()
dc.Close()
Exit Sub
Catch
MessageBox.Show ("Error occured when trying to save data!",
"Sale", MessageBoxButto ns.OK, MessageBoxIcon. Exclamation)
txtItemCode.Foc us()
Exit Sub
End Try
txtItemCode.Foc us()
txtItemCode.Cle ar()
txtDescription. Clear()
NumericUpDown1. Text = 1
txtUnitPrice.Cl ear()
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