When I use the OleDb to connect a Oracle db, and use the
ExecutScalar() method to get the count of a table, the
return value can't be cast to a data type, say int, while
this works fine for a SQL server db using SqlCommand.
Following is the code example:
string strCnt = "SELECT count (*) from B_PlanSchemeIte ms";
string strSource="Prov ider=MSDAORA;Da ta
Source=avocet1; User ID=dbo; Password=mmsmms ;";
OleDbConnection conn = new OleDbConnection (strSource);
conn.Open();
OleDbCommand cmdCount = new OleDbCommand(st rCnt,conn);
object objInt;
objInt = cmdCount.Execut eScalar();
intNumRecs = (int) (objInt);
The run time error occurs with message:
"Specified cast is not valid"
Following code works fine for a SQL server db:
string strCnt = "SELECT count (*) from B_PlanSchemeIte ms";
string
strSource="serv er=planserv1;ui d=sa;pwd=sysadm in;database=a
vocet1";
SqlConnection myConn = new SqlConnection(s trSource);
myConn.Open();
SqlCommand cmdCount = new SqlCommand(strC nt, myConn);
intNumRecs = (int) cmdCount.Execut eScalar();
Can anyone help me on solving the cast problem in OleDb
case? Thanks.
ExecutScalar() method to get the count of a table, the
return value can't be cast to a data type, say int, while
this works fine for a SQL server db using SqlCommand.
Following is the code example:
string strCnt = "SELECT count (*) from B_PlanSchemeIte ms";
string strSource="Prov ider=MSDAORA;Da ta
Source=avocet1; User ID=dbo; Password=mmsmms ;";
OleDbConnection conn = new OleDbConnection (strSource);
conn.Open();
OleDbCommand cmdCount = new OleDbCommand(st rCnt,conn);
object objInt;
objInt = cmdCount.Execut eScalar();
intNumRecs = (int) (objInt);
The run time error occurs with message:
"Specified cast is not valid"
Following code works fine for a SQL server db:
string strCnt = "SELECT count (*) from B_PlanSchemeIte ms";
string
strSource="serv er=planserv1;ui d=sa;pwd=sysadm in;database=a
vocet1";
SqlConnection myConn = new SqlConnection(s trSource);
myConn.Open();
SqlCommand cmdCount = new SqlCommand(strC nt, myConn);
intNumRecs = (int) cmdCount.Execut eScalar();
Can anyone help me on solving the cast problem in OleDb
case? Thanks.
Comment