Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OleDbConnection syntax

Status
Not open for further replies.

buddyel

MIS
Mar 3, 2002
279
0
0
US

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
 
dim objCommand=New Oledb.OledbCommand
Dim sConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\Development\Databases\STNDCARDS.mdb;"
Dim strSQL As String = "INSERT INTO tblTemp (CATALOG_NO, WO, CUST_NAME)" & "VALUES ('" & PART & "', '" & WORK & "', '" & CUST & "')"
dim drReader as oledb.oledbdatareader
dim Exists as boolean=false

With objCommand
.Connection = New Oledb.OleDbConnection(sConnString)
.connection.open
.commandtext="Put select statement here"
drreader=.executereader
End With

do while drreader.read
exists=true
Loop
drreader.close
if exists=true then
With objCommand
.CommandText = strSQL
dim i as int16=.ExecuteNonQuery()
End With
objCommand.close
if i=1 then
messagebox.show("1 Record Updated")
end if
end if



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top