0

I used DataAdapter for use SELECT common to choose rows of Table

OleDbDataAdapter objDataAdapter = new OleDbDataAdapter("SELECT * FROM Table WHERE dayNum = @dayNum", objConnection);  //here dayNum must be equal to 10; dayNum = 10

I want assign an integer value to @dayNum

for example

int intDay = 10;
objCommand.Parameters.AddWithValue(intDay.ToString(),"@dayNum");

but it don't work

how can fix this problem?

7
  • what about objCommand.Parameters.AddWithValue("@dayNum",dayNum); Commented Apr 1, 2015 at 15:46
  • Where have you defined objCommand and how it is related to objDataAdapter, looks like you are using command text in DataAdapter instead of using existing Command Object, also swap parameter name and value in adding parameter. Commented Apr 1, 2015 at 15:49
  • i need use it after WHERE keycode, It's not possible, i guess Commented Apr 1, 2015 at 15:50
  • @ali:- I suppose dayNum is the name of the column of your table Commented Apr 1, 2015 at 15:52
  • @Habib objCommand it's not important, i just had an example for asaign integer value, I just need a way for asaign int to select string, it was very simple in php language , but i don't know how can i do it in C# Commented Apr 1, 2015 at 15:55

2 Answers 2

1

The first argument is the parameter name and the second the value, so:

objCommand.Parameters.AddWithValue("@dayNum", intDay); // use the correct type not string
Sign up to request clarification or add additional context in comments.

Comments

0

Remove the .ToString(). Try this:

objCommand.Parameters.AddWithValue("@dayNum",intDay);

1 Comment

function "System.Data.OleDb.OleDbParameterCollection.AddWithValue" cannot be called with the given argument list argument types are: (int, const char [8]) object type is: System.Data.OleDb.OleDbParameterCollection

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.