Monday, March 12, 2012

Works in VB but not in C#, why?

This statement works in VB.NET:
cmd.Parameters.Add(New OracleParameter("input_string", OracleType.VarChar)).Value = "A"

This give ne a syntax error in C#
cmd.Parameters.Add(new OracleParameter("input_string", OracleType.VarChar)).value = "A";

Any ideas how why the C# statement doesn't work?

OracleParameter prm1 =new OracleParameter("Code1",OracleDbType.Varchar2);
prm1.Direction = ParameterDirection.Input;
prm1.Value = sCode1;
cmd.Parameters.Add(prm1);

Try this:

cmd.Parameters.Add(newOracleParameter("input_string","A").OracleType =OracleType.VarChar);


I know both of these solutions will work but I am wondering why my C# statement won't work.

Thanks,

Paul


What is the syntax error? Does the "V" in value upper case or lower case in your code. I think it should be upper case.


Does this work?

cmd.Parameters.Add("input_string", OracleType.VarChar).value = "A";


It works if I use an upper case V. What was throwing me off was that I was relying on intellisence and it would give me the .Value as an option here:

cmd.Parameters.Add(newOracleParameter("userid_in",OracleType.VarChar).

Not here:

cmd.Parameters.Add(newOracleParameter("userid_in",OracleType.VarChar))

Any ideas why intellisence is not working in this case?


I am able to get intellisense to work using SqlParameters and you syntax above, but just like you I am unable to have intellisense work with oracle. Might just be a limitation to the OracleClient


Did you add reference to System.Data.OracleClient.dll?


hd181a:

It works if I use an upper case V. What was throwing me off was that I was relying on intellisence and it would give me the .Value as an option here:

cmd.Parameters.Add(newOracleParameter("userid_in",OracleType.VarChar).

Not here:

cmd.Parameters.Add(newOracleParameter("userid_in",OracleType.VarChar))

Any ideas why intellisence is not working in this case?

Hi Hd181a,

Based on my understanding, the intellisence is working when you press dot in the end of cmd.Parameters.Add(new OracleParameter("userid_in", OracleType.VarChar); But it is not working when you press dot in the end of cmd.Parameters.Add(new OracleParameter("userid_in", OracleType.VarChar)). If I have misunderstood you, please feel free to let me know.

When you press dot in the end of cmd.Parameters.Add(new OracleParameter("userid_in", OracleType.VarChar), new OracleParameter("userid_in", OracleType.VarChar) is the object which has a Value property. So the intellisence is working. When you press dot in the end of cmd.Parameters.Add(new OracleParameter("userid_in", OracleType.VarChar)), cmd.Parameters.Add() is a method which does not have a Value property.


I hope this helps.

0 comments:

Post a Comment