I have another posting (adodb syntax) which is similar to this problem, this is just a slight variation. I guess I will use whatever one I can get working first.
I would like the program to check the database for an existance of a record for a part number then ask the user to update..
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\Development\Databases\STNDCARDS.mdb;"
Dim oOleDbConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection(sConnString)
Dim objCommand As New OleDb.OleDbCommand()
Dim strSQL As String
strSQL = "INSERT INTO tblTemp (CATALOG_NO, WO, CUST_NAME)" & "VALUES ('" & PART & "', '" & WORK & "', '" & CUST & "')"
oOleDbConnection.Open()
With objCommand
.Connection = oOleDbConnection
.CommandText = checkdb
End With
oOleDbConnection.Open()
With objCommand
.Connection = oOleDbConnection
.CommandText = strSQL
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
objDBConnection.Close()
oOleDbConnection = Nothing
objCommand = Nothing
I think it should be similiar syntax to some VBA code i have, I just am not sure of the proper syntax.
rs.open = "SELECT * from tblTemp where [CATALOG_NO] = '" & PART & "'"
With rs
if .RecordCount > 0 then
ExistingRecord = True
Else
ExistingRecord = False
End if
if ExistingRecord = True Then
prmptUser = Msgbox("Record already exists - Update Record ?",vbYesNo,"What to do?"
if prmptUser = vbYes then
.Update
Msgbox("Record Updated"
Else
Exit Sub
End if
Else
.Addnew
.Update
Msgbox("Record Added"
end if
rs.close
set rs = nothing
cn.close
set cn = nothing