Going from SqlConnection to OleDbConnection

C

Charles

Hello,
In an effort to have my code "more generic" I'm converting
my data connection code from System.Data.SQLClient to just
System.Data ie no more SQL specific methods and properties
but more generic OleDB methods and properties.

The problem is I'm now getting the error "too many
arguments specified" on the "command.ExecuteNonQuery()"
statement!

Any suggestions?
Charles
 
C

Carl Prothman [MVP]

Charles said:
In an effort to have my code "more generic" I'm converting
my data connection code from System.Data.SQLClient to just
System.Data ie no more SQL specific methods and properties
but more generic OleDB methods and properties.
The problem is I'm now getting the error "too many
arguments specified" on the "command.ExecuteNonQuery()"
statement!

Charles,
Try using ADO.NET's base classes for a "generic" solution.
http://support.microsoft.com/default.aspx?scid=kb;en-us;308046

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com
 
C

Charles Wildner

Hello,
Is this enough?
This is the error line:
rowsAffected = command.ExecuteNonQuery()

Charles

Public Function SaveCategories(ByVal CatID As Integer, ByVal CatName As
String, ByVal CatDesc As String, ByVal CatStatus As String, ByVal
rowsAffected As Integer) As Integer
Dim parameters As OleDb.OleDbParameter() = { _
New OleDb.OleDbParameter("@CatID", OleDb.OleDbType.Integer), _
New OleDb.OleDbParameter("@CatName", OleDb.OleDbType.VarChar, 50), _
New OleDb.OleDbParameter("@CatDesc", OleDb.OleDbType.VarChar, 50), _
New OleDb.OleDbParameter("@CatStatus", OleDb.OleDbType.Char, 1)}

parameters(0).Value = CatID
parameters(1).Value = CatName
parameters(2).Value = CatDesc
'parameters(3).Value = CatStatus
If CatStatus Then
parameters(3).Value = "A"
Else
parameters(3).Value = "I"
End If

Dim NewCatID As Integer
NewCatID = RunProcedure("Invt_Categories_Save", parameters,
rowsAffected)

Return NewCatID
End Function

Protected Overloads Function RunProcedure( _
ByVal storedProcName As String, _
ByVal parameters As IDataParameter(), _
ByRef rowsAffected As Integer) _
As Integer

Dim result As Integer

MyConnection.Open()
'' Dim command As SqlCommand = BuildIntCommand(storedProcName,
parameters)
Dim command As OleDb.OleDbCommand =
BuildIntCommand(storedProcName, parameters)
rowsAffected = command.ExecuteNonQuery()
result = CInt(command.Parameters("ReturnValue").Value)
MyConnection.Close()

Return result

End Function

Private Function BuildIntCommand( _
ByVal storedProcName As String, _
ByVal parameters As IDataParameter()) _
As OleDb.OleDbCommand
'' As SqlCommand

'' Dim command As SqlCommand = _
Dim command As OleDb.OleDbCommand = _
BuildQueryCommand(storedProcName, parameters)
'' Dim parameter As New SqlParameter
Dim parameter As New OleDb.OleDbParameter

With parameter
.ParameterName = "ReturnValue"
.DbType = OleDb.OleDbType.Integer ' SqlDbType.Int
.Size = 4
.Direction = ParameterDirection.ReturnValue
.IsNullable = False
.Precision = 0
.Scale = 0
.SourceColumn = String.Empty
.SourceVersion = DataRowVersion.Default
.Value = Nothing
End With
command.Parameters.Add(parameter)

Return command

End Function
 
K

Kathleen Dollard

Charles,

Does OLEDB expect the RetrunValue as the first parameter.

I would look for something that relates to the message - you didn't show us
the stored proc declaration, which would be helpful.

Kathleen
 

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