How to excute a MS Access Stored procedure?

P

Peter

Hi, there

I have create a MS Access Stored procedure using the code below and no error
occured.


'---------------------------------------------------------------------------
---
Dim cmd As OleDbCommand
cmd = Conn.CreateCommand
cmd.CommandType = CommandType.Text

Try
cmd.CommandText = _
"CREATE PROC udpGetSampleIDByName" & vbCrLf & _
"(@zSampleName VarChar(64))" & vbCrLf & _
"AS" & vbCrLf & _
"Select zSampleID FROM TSamples " & _
"Where zSampleName = @zSampleName "
cmd.ExecuteNonQuery()

Catch e As Exception
MessageBox.Show(e.ToString, "Error Creating Stored Procedure")
Finally
cmd.Dispose()
End Try
'---------------------------------------------------------------------------
------

And now I want to call the Stored procedure with OleDBCommand . After I
excute the codes below I got an error message: "The syntax of the input
string is invalid!"

'---------------------------------------------------------------------------
------
'connNoTran is an opened oledbconnection
Dim oCmd As New OleDbCommand

With oCmd
.Connection = connNoTran
.CommandType = CommandType.StoredProcedure
.CommandText = "udpGetSampleIDByName"

.Parameters.Add("", OleDbType.SmallInt)
.Parameters(0).Value = sName
End With

Try

oCmd.ExecuteNonQuery()

Catch e As Exception
MessageBox.Show(e.ToString)
End Try

'---------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top