OleDbParameter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to use a parameter to retrieve some entry from my Oracle table

I used Microsfot OleDB Provider for Oracle

Here are the codes
cmd.CommandText="select * from users where user_name= ?")
cmd.Parameters.Add("@user_name",OleDbType.Char,60).Value="jt5289"
da.SelectCommand=cmd;
da.Fill(ds,"Results")

But I cannot get the result I want, it returned 0 rows

I used tool(SQL Monitor) and it showed me the SQL I used
select * from users where user_name= :V0000
:V00001 = 'jt5289

Is there something wrong with this

If I type in select * from users where user_name='jt5289' it returns me the one row I wanted

Thanks
 
Junchi,
Is a Char column in Oracle a null terminated (i.e. variable length)
string? I don't have an Oracle instance up right now so I can't check. You
might want to set the OleDbType to VarChar just to test this.

Ron Allen
 
¤ I am trying to use a parameter to retrieve some entry from my Oracle table.
¤
¤ I used Microsfot OleDB Provider for Oracle.
¤
¤ Here are the codes :
¤ cmd.CommandText="select * from users where user_name= ?");
¤ cmd.Parameters.Add("@user_name",OleDbType.Char,60).Value="jt5289";
¤ da.SelectCommand=cmd;
¤ da.Fill(ds,"Results");
¤
¤ But I cannot get the result I want, it returned 0 rows.
¤
¤ I used tool(SQL Monitor) and it showed me the SQL I used.
¤ select * from users where user_name= :V00001
¤ :V00001 = 'jt5289'
¤
¤ Is there something wrong with this?
¤
¤ If I type in select * from users where user_name='jt5289' it returns me the one row I wanted.

Not sure what Oracle data type user_name is, but does it work any differently if you specify the
parameter type as OleDb.OleDbType.VarChar or OleDbType.VarWChar?


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Guys, I have to apologize first, the code I posted is actually A WORKING VERSION.
It is fixed after I changed from OleDbType.VarChar to OleDbType.Char
I am so sorry..

I think the problem is I was trying to map Oracle Char type to .NET OleDbType.Varchar type

Still have a question, what is difference between a Char AND A Varchar, how .NET handle the 3rd parameter(size) of Add method? Is it important for Char type, I changed it to different values, it is all working

Thank you
 
¤ Guys, I have to apologize first, the code I posted is actually A WORKING VERSION.
¤ It is fixed after I changed from OleDbType.VarChar to OleDbType.Char.
¤ I am so sorry...
¤
¤ I think the problem is I was trying to map Oracle Char type to .NET OleDbType.Varchar type.
¤
¤ Still have a question, what is difference between a Char AND A Varchar, how .NET handle the 3rd parameter(size) of Add method? Is it important for Char type, I changed it to different values, it is all working.

In Oracle, a Char data type is a fixed length field and VarChar is a variable length field.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top