F
Frank
Hello,
I am attempting to retrieve a numeric type froma a table.
I get an invalid cast exception when I use the following code in my data
layer:
//The problem definitley occurs in the line"id = (int)
cmdSelect.ExecuteScalar();"
public int GetId(string handle)
{
string strSelect = null;
SqlCommand cmdSelect;
int id = 0;
strSelect = "Select [ID] FROM members WHERE handle = @handle";
SqlConnection conDb = new SqlConnection( _connStr );
cmdSelect = new SqlCommand(strSelect, conDb);
cmdSelect.Parameters.Add("@handle", handle);
conDb.Open();
id = (int) cmdSelect.ExecuteScalar();
conDb.Close();
return id;
}
So how does one normally extract a numeric type? Do I have to cast it as a
decimal or double?
Thanks in advance.
Frank
I am attempting to retrieve a numeric type froma a table.
I get an invalid cast exception when I use the following code in my data
layer:
//The problem definitley occurs in the line"id = (int)
cmdSelect.ExecuteScalar();"
public int GetId(string handle)
{
string strSelect = null;
SqlCommand cmdSelect;
int id = 0;
strSelect = "Select [ID] FROM members WHERE handle = @handle";
SqlConnection conDb = new SqlConnection( _connStr );
cmdSelect = new SqlCommand(strSelect, conDb);
cmdSelect.Parameters.Add("@handle", handle);
conDb.Open();
id = (int) cmdSelect.ExecuteScalar();
conDb.Close();
return id;
}
So how does one normally extract a numeric type? Do I have to cast it as a
decimal or double?
Thanks in advance.
Frank