squashjunkie
New member
- Joined
- Jul 6, 2005
- Messages
- 2
- Programming Experience
- Beginner
Hi,
I am trying to update two fields in a database at the same time with the following code......
Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
Dim con As OleDb.OleDbConnection = OleDbConnection2
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim paramdaystilldue As New OleDb.OleDbParameter
Dim paramsysdocid As New OleDb.OleDbParameter
Dim paramspare As New OleDb.OleDbParameter
Dim upSYSDOCID As Integer = CInt(lblsysdocid.Text)
Dim upDAYSTILLDUE As Integer = CInt(LBLDUEDAYS.Text)
cmd.Connection = con
With paramsysdocid
.ParameterName = "sysdocid"
.OleDbType = OleDb.OleDbType.Integer
.Size = 5
.Value = upSYSDOCID
End With
cmd.Parameters.Add(paramsysdocid)
With paramspare
.ParameterName = "Spare"
.OleDbType = OleDb.OleDbType.BSTR
.Size = 32
.Value = "U"
End With
cmd.Parameters.Add(paramspare)
With paramdaystilldue
.ParameterName = "DAYSTILLDUE"
.OleDbType = OleDb.OleDbType.Integer
.Size = 5
.Value = upDAYSTILLDUE
End With
cmd.Parameters.Add(paramdaystilldue)
MsgBox("Update Database?", MsgBoxStyle.OKCancel, "Update")
If MsgBoxResult.OK = 1 Then
con.Open()
cmd.CommandText = "UPDATE ARTRAN SET DAYSTILLDUE = " & CStr(LBLDUEDAYS.Text) & " WHERE SYSDOCID = " & CStr(lblsysdocid.Text)
cmd.CommandText = "UPDATE ARTRAN SET Spare = " & "U" & " WHERE SYSDOCID = " & CStr(lblsysdocid.Text)
cmd.ExecuteNonQuery()
con.Close()
End If
End Sub
However the code is failing at the UPDATE ARTRAN SPARE comand line. If I rem this line out, the update works fine, but with it in, the update crashes. The SPARE field is a string field, and the DAYSTILLDUE field is a numeric field.
Can anyone help?
TIA
P.S. My first project so I must apologise for the scrappy code and "extra" lines!
I am trying to update two fields in a database at the same time with the following code......
Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
Dim con As OleDb.OleDbConnection = OleDbConnection2
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim paramdaystilldue As New OleDb.OleDbParameter
Dim paramsysdocid As New OleDb.OleDbParameter
Dim paramspare As New OleDb.OleDbParameter
Dim upSYSDOCID As Integer = CInt(lblsysdocid.Text)
Dim upDAYSTILLDUE As Integer = CInt(LBLDUEDAYS.Text)
cmd.Connection = con
With paramsysdocid
.ParameterName = "sysdocid"
.OleDbType = OleDb.OleDbType.Integer
.Size = 5
.Value = upSYSDOCID
End With
cmd.Parameters.Add(paramsysdocid)
With paramspare
.ParameterName = "Spare"
.OleDbType = OleDb.OleDbType.BSTR
.Size = 32
.Value = "U"
End With
cmd.Parameters.Add(paramspare)
With paramdaystilldue
.ParameterName = "DAYSTILLDUE"
.OleDbType = OleDb.OleDbType.Integer
.Size = 5
.Value = upDAYSTILLDUE
End With
cmd.Parameters.Add(paramdaystilldue)
MsgBox("Update Database?", MsgBoxStyle.OKCancel, "Update")
If MsgBoxResult.OK = 1 Then
con.Open()
cmd.CommandText = "UPDATE ARTRAN SET DAYSTILLDUE = " & CStr(LBLDUEDAYS.Text) & " WHERE SYSDOCID = " & CStr(lblsysdocid.Text)
cmd.CommandText = "UPDATE ARTRAN SET Spare = " & "U" & " WHERE SYSDOCID = " & CStr(lblsysdocid.Text)
cmd.ExecuteNonQuery()
con.Close()
End If
End Sub
However the code is failing at the UPDATE ARTRAN SPARE comand line. If I rem this line out, the update works fine, but with it in, the update crashes. The SPARE field is a string field, and the DAYSTILLDUE field is a numeric field.
Can anyone help?
TIA
P.S. My first project so I must apologise for the scrappy code and "extra" lines!