I've been coding for years but I'm relatively new to ASP/C#. This is my code; the exception occurs on the ExecuteScalar() command.
I've been back through it several times and I can't find anything that I haven't instantiated. Any ideas anyone?
Thanks
Bertha
Code:
protected void ect_txt_TextChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connect_str); // connect_str good as it works elsewhere
string ecr_num_txt = ecr_txt.Text; // exr_txt is <asp:TextBox ID>
int ecr_num_int = int.Parse(ecr_num_txt);
int ecr_exists = 0;
SqlCommand cmd = new SqlCommand("ecr_exists_proc", conn); // ecr_exists_proc returns 1 or 0
SqlParameter param = cmd.Parameters.Add("@ecr_id", SqlDbType.Int);
cmd.Parameters["@ecr_id"].Value = ecr_num_int;
cmd.CommandType = CommandType.StoredProcedure;
param.Direction = ParameterDirection.Input;
try
{
conn.Open();
ecr_exists = (int)cmd.ExecuteScalar();
. . .
I've been back through it several times and I can't find anything that I haven't instantiated. Any ideas anyone?
Thanks
Bertha