How to use ExecuteReader() with Oracle DB?
-
hi, In my appication i'm using Oracle as a back end. In that when i'm using ExecuteReader() it shows an exception. Can any one of help me to solve this issue.
oleDBConnection = new OleDbConnection(connectString); string query = "SELECT V_FIRST_NAME,V_LAST_NAME,V_PHONE_NUMBER,V_EMAIL,V_FAX_NUMBER,V_ADDRESS,V_TITLE,V_POSTAL_CODE,V_COUNTRY from UserDetails where (V_USER_ID = ?) AND (V_PASSWORD = ?)"; OleDbCommand oledbCmd = new OleDbCommand(query, oleDBConnection); oledbCmd.CommandText = query; oledbCmd.CommandType = CommandType.Text; OleDbParameter par = oledbCmd.Parameters.Add("UserName", OleDbType.VarWChar, 50); OleDbParameter parm = oledbCmd.Parameters.Add("password", OleDbType.VarWChar, 50); oledbCmd.Parameters["UserName"].Value = userName; oledbCmd.Parameters["password"].Value = password; oledbCmd.Connection = oleDBConnection; oleDBConnection.Open(); OleDbDataReader dr ; dr = oledbCmd.ExecuteReader();
It threw an exception when executing the last line. The exception states that Unspecified error.Oracle error occured,but error message could not retrieved from Oracle.Data Type is not supported. Thanks in advance Babu -
hi, In my appication i'm using Oracle as a back end. In that when i'm using ExecuteReader() it shows an exception. Can any one of help me to solve this issue.
oleDBConnection = new OleDbConnection(connectString); string query = "SELECT V_FIRST_NAME,V_LAST_NAME,V_PHONE_NUMBER,V_EMAIL,V_FAX_NUMBER,V_ADDRESS,V_TITLE,V_POSTAL_CODE,V_COUNTRY from UserDetails where (V_USER_ID = ?) AND (V_PASSWORD = ?)"; OleDbCommand oledbCmd = new OleDbCommand(query, oleDBConnection); oledbCmd.CommandText = query; oledbCmd.CommandType = CommandType.Text; OleDbParameter par = oledbCmd.Parameters.Add("UserName", OleDbType.VarWChar, 50); OleDbParameter parm = oledbCmd.Parameters.Add("password", OleDbType.VarWChar, 50); oledbCmd.Parameters["UserName"].Value = userName; oledbCmd.Parameters["password"].Value = password; oledbCmd.Connection = oleDBConnection; oleDBConnection.Open(); OleDbDataReader dr ; dr = oledbCmd.ExecuteReader();
It threw an exception when executing the last line. The exception states that Unspecified error.Oracle error occured,but error message could not retrieved from Oracle.Data Type is not supported. Thanks in advance Babubabutkchn wrote:
string query = "SELECT V_FIRST_NAME,V_LAST_NAME,V_PHONE_NUMBER,V_EMAIL,V_FAX_NUMBER,V_ADDRESS,V_TITLE,V_POSTAL_CODE,V_COUNTRY from UserDetails where (V_USER_ID = ?) AND (V_PASSWORD = ?)";
You add parameters to the query, but you don't specify anywhere these parameters. Try this
string query = "SELECT V_FIRST_NAME,V_LAST_NAME,V_PHONE_NUMBER,V_EMAIL,V_FAX_NUMBER,V_ADDRESS,V_TITLE,V_POSTAL_CODE,V_COUNTRY from UserDetails where (V_USER_ID = @UserName) AND (V_PASSWORD = @password)";
OleDbCommand oledbCmd = new OleDbCommand(query, oleDBConnection);
oledbCmd.CommandText = query;oledbCmd.CommandType = CommandType.Text;
OleDbParameter par = oledbCmd.Parameters.Add("@UserName", OleDbType.VarWChar, 50);
OleDbParameter parm = oledbCmd.Parameters.Add("@password", OleDbType.VarWChar, 50);Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
-
babutkchn wrote:
string query = "SELECT V_FIRST_NAME,V_LAST_NAME,V_PHONE_NUMBER,V_EMAIL,V_FAX_NUMBER,V_ADDRESS,V_TITLE,V_POSTAL_CODE,V_COUNTRY from UserDetails where (V_USER_ID = ?) AND (V_PASSWORD = ?)";
You add parameters to the query, but you don't specify anywhere these parameters. Try this
string query = "SELECT V_FIRST_NAME,V_LAST_NAME,V_PHONE_NUMBER,V_EMAIL,V_FAX_NUMBER,V_ADDRESS,V_TITLE,V_POSTAL_CODE,V_COUNTRY from UserDetails where (V_USER_ID = @UserName) AND (V_PASSWORD = @password)";
OleDbCommand oledbCmd = new OleDbCommand(query, oleDBConnection);
oledbCmd.CommandText = query;oledbCmd.CommandType = CommandType.Text;
OleDbParameter par = oledbCmd.Parameters.Add("@UserName", OleDbType.VarWChar, 50);
OleDbParameter parm = oledbCmd.Parameters.Add("@password", OleDbType.VarWChar, 50);Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
-
we are using oracle not sql server('@symbol is not supported in Oracle'). give me the solution
Ok, my bad. But still, you have to find a way to specify the parameters in the query. I think that that's your problem.
There are 10 kinds of people: those who understand binary and those who don't