T
Timothy.Rybak
Hello all,
This is my first attempt at an application, so kid gloves are
appreciated.
I need to make a very simple form that only has a few elements. One is
TraceCode - a text field that is populated when a user scans a label.
The other is ScanDate - a date/time field that should equal the
date/time of the scan (e.g. 7/31/2006 5:00:00 AM).
When a button is clicked, or Enter is pressed on the keyboard (or as
the last character of the scan), the data should be transmitted to a
SQL table, and the two text field should be cleared and ready for the
next scan.
Currently, I have a simple form, but you have to manually type the
ScanDate. Also, the fields don't clear after the update is successful.
Ideally, there would only be one textbox available to the user, and
when they scan the TraceCode, the ScanDate is automatically populated,
the data is transacted to the SQL table, and the fields clear, ready
for the next scan.
Here is the only code I have, and it is for the "GO" button":
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim objConnection As New SqlClient.SqlConnection _
("server=.;database=SafetyStock;trusted_connection=true")
Dim objCommand As New SqlClient.SqlCommand("", objconnection)
Dim objTransaction As SqlClient.SqlTransaction, strSQL As
String
Try
objConnection.Open()
objTransaction = objConnection.BeginTransaction
objCommand.Transaction = objTransaction
strSQL = "INSERT INTO ActiveSafetyStock(ScanDate,
TraceCode) " & _
"VALUES('" & txtDatetime.Text & "', '" &
txtTraceCode.Text & "')"
objCommand.CommandText = strSQL
objCommand.ExecuteNonQuery()
objTransaction.Commit()
objConnection.Close()
Catch
Button1.Text = "Failed"
objTransaction.Rollback()
objConnection.Close()
End Try
End Sub
End Class
Please HELP!
This is my first attempt at an application, so kid gloves are
appreciated.
I need to make a very simple form that only has a few elements. One is
TraceCode - a text field that is populated when a user scans a label.
The other is ScanDate - a date/time field that should equal the
date/time of the scan (e.g. 7/31/2006 5:00:00 AM).
When a button is clicked, or Enter is pressed on the keyboard (or as
the last character of the scan), the data should be transmitted to a
SQL table, and the two text field should be cleared and ready for the
next scan.
Currently, I have a simple form, but you have to manually type the
ScanDate. Also, the fields don't clear after the update is successful.
Ideally, there would only be one textbox available to the user, and
when they scan the TraceCode, the ScanDate is automatically populated,
the data is transacted to the SQL table, and the fields clear, ready
for the next scan.
Here is the only code I have, and it is for the "GO" button":
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim objConnection As New SqlClient.SqlConnection _
("server=.;database=SafetyStock;trusted_connection=true")
Dim objCommand As New SqlClient.SqlCommand("", objconnection)
Dim objTransaction As SqlClient.SqlTransaction, strSQL As
String
Try
objConnection.Open()
objTransaction = objConnection.BeginTransaction
objCommand.Transaction = objTransaction
strSQL = "INSERT INTO ActiveSafetyStock(ScanDate,
TraceCode) " & _
"VALUES('" & txtDatetime.Text & "', '" &
txtTraceCode.Text & "')"
objCommand.CommandText = strSQL
objCommand.ExecuteNonQuery()
objTransaction.Commit()
objConnection.Close()
Catch
Button1.Text = "Failed"
objTransaction.Rollback()
objConnection.Close()
End Try
End Sub
End Class
Please HELP!