How to used AddParameter method to add parameter?

B

Benny Ng

Now I'm used MS Enterprise Library to insert data into DataGrid.

But an statement error in AddParameter in the following:

Database db = DatabaseFactory.CreateDatabase("Database Instance NorthWind");
string sqlCommand = "Select CustomerID, CompanyName, ContactName From
Customers";
DBCommandWrapper dbCommandWrapper =
db.GetSqlStringCommandWrapper(sqlCommand);
//dbCommandWrapper.AddParameter("@CustomerID","FRANK") ; <--Error

But how to used this method? seems many parameter should be insert into
this. in this case, i want to search the datas where CustomerID="FRANK", and
return it.

How to solve it?

Any suggestion are appreciated. Thanks.
 
B

Ben

Benny,

The AddParameter method of the DBCommandWrapper doesn't have an overload
that takes only two parameters.

You'll need to provide a match to one of the two overloads for AddParameter.
string name, DbType dbType, ParameterDirection direction,
string sourceColumn, DataRowVersion sourceVersion, object value

or

string name, DbType dbType, int size, ParameterDirection direction,
bool nullable, byte precision, byte scale, string sourceColumn,
DataRowVersion sourceVersion, object value

HTH,
Ben
 
B

Benny Ng

Yes,Thanks first.

I just found the usage of this method. But unfortunately I don't know how to
full fill all parameters into this statement. So, any sample can give helps
me?

public abstract new void AddParameter ( System.String name ,
System.Data.DbType dbType , System.Data.ParameterDirection direction ,
System.String sourceColumn , System.Data.DataRowVersion sourceVersion ,
System.Object value )
 
B

Benny Ng

Oh,Yes!

Problem solved!

At first, I misunderstand that the AddInParameter is only for
StoreProcedure. But just now when I try to used this for run SQL statement.
Successed it.

Use AddInParameter, Not AddParameter.(maybe AddParameter also can,But
actually haven't enough time to try it).

Thank you!!

Benny Ng
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top