Reputation: 4721
I am trying to get the String
value in a list but getting error as
Input string was not in a correct format.
There are many helpful links available on the net but didn't resolved mine one.
Here is my code.
newRow["EXP_TYPE_ID"] = Convert.ToString(e.Record["EXP_TYPE"]);
newRow["EXP_TYPE"] = CF.ExecuteScaler("Select Type_desc from type_mst where Type_Code = 'PAR' and Type_Abbr ='" + Convert.ToString(e.Record["EXP_TYPE"]) + "'").ToString();
and CF.ExecuteScaler
public string ExecuteScaler(string StrQuery)
{
DB.EConnection();
cmd = new OracleCommand(StrQuery, DB.conn);
cmd.Connection = DB.conn;
int val=Convert.ToInt32(cmd.ExecuteScalar());
DB.conn.Close();
string ret = val.ToString();
return ret;
}
Note I can't change Scaler function.
update
StrQuery = Select Type_desc from type_mst where Type_Code = 'PAR' and Type_Abbr ='PUR'
and the value of the query
PURCHASER
Upvotes: 0
Views: 1134
Reputation: 6310
I believe the exception is thrown in the following line?
int val=Convert.ToInt32(cmd.ExecuteScalar());
As you have said, cmd.ExecuteScalar()
returns value "PURCHASER"
, which then you are trying to convert into int
. That is clearly not possible, and this is what the exception is saying.
Please try it like that:
public string ExecuteScaler(string StrQuery)
{
DB.EConnection();
cmd = new OracleCommand(StrQuery, DB.conn);
cmd.Connection = DB.conn;
string ret = Convert.ToString(cmd.ExecuteScalar());
DB.conn.Close();
return ret;
}
Upvotes: 1