0

I want to insert data from c# form into oracle database .... I use this line of code

com.CommandText = "insert into DEPTS VALUES (:code, :name)";
com.Parameters.Add(new OracleParameter(
    "code", OracleType.Int32,dept_cod_txt.Text, ParameterDirection.Input));
com.Parameters.Add(new OracleParameter(
    "name", OracleType.NVarChar, dept_name_txt.Text , ParameterDirection.Input));
com.ExecuteNonQuery();`

it gives me some errors as below : enter image description here

5
  • ok i change my image link Commented Mar 12, 2014 at 15:05
  • 1
    Don't use an image at all to show text. Copy and paste the actual text. Also, @GrantWinney, surely you can come up with something better than "enter image description here"? Commented Mar 12, 2014 at 15:26
  • @mohsen.d - Text is preferable for code and error messages, because it is more permanent (no worry of broken links) and unlike an image, it can be copied and pasted. Commented Mar 12, 2014 at 15:47
  • @Leigh , yes. I added the errors text at first place when he added a link to an external image. then when he added the image here , I removed my edit. you are right anyway. Commented Mar 12, 2014 at 15:57
  • @mohsen.d - Ah, I did not realize you were the one to "add" the text. Thanks, text is much better than a transient image. Commented Mar 12, 2014 at 16:03

1 Answer 1

1

you are adding wrong parameters.

you should use it like this

new OracleParameter(
"parameterName", OracleType, length, "db column name");

suppose your table fields are code and name. then

var codeParameter = new OracleParameter(
"code", OracleType.Int32, 4, "code");

codeParameter.Value = Convert.ToInt32(dept_cod_txt.Text);

var nameParameter = new OracleParameter(
"name", OracleType.NVarchar, 20, "name");

nameParameter.Value = dept_name_txt.Text;

com.Parameters.Add(codeParameter);
com.Parameters.Add(nameParameter);

the one with ParameterDirection parameter has a different signature.

you can find a list of all possible signatures here

Sign up to request clarification or add additional context in comments.

2 Comments

can you give me more detail please ... what js parameterName,length and db column name?
thank you mohsen.d my problem is solved ... but if you can i need to do the same thing for delete,update,select query can you help me?? share the same code for delete,update and select query

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.