When i run the code below, i get an error
Error 2 Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?)
Expand|Select|Wrap|Line Numbers
- protected void btnSearch_Click(object sender, EventArgs e)
- {
- string constring = ConfigurationManager.AppSettings.Get("con").ToString();
- SqlConnection conn = new SqlConnection(constring);
- conn.Open();
- SqlCommand check = new SqlCommand("spSearchCombo", conn);
- check.CommandType = CommandType.StoredProcedure;
- check.Parameters.Add(new SqlParameter("@searchBy", SqlDbType.NVarChar, 50));
- check.Parameters["@searchBy"].Value = ddlSearchBy.SelectedItem.Value.ToString();
- check.Parameters.Add(new SqlParameter("@searchKey", SqlDbType.NVarChar, 50));
- check.Parameters["@searchKey"].Value = txtSearch.Text;
- //@no_rows=@@rowcount in stored procedure
- check.Parameters.Add(new SqlParameter("@no_rows",SqlDbType.Int));
- check.Parameters["@no_rows"].Direction = ParameterDirection.Output;
- int result = check.Parameters["@no_rows"].Value;
- if (result >0)
- {
- SqlDataAdapter da = new SqlDataAdapter(check);
- DataSet ds = new DataSet();
- da.Fill(ds);
- this.dgv1.DataSource = ds.Tables[0].DefaultView;
- dgv1.DataBind();
- conn.Close();
- }
- else
- {
- Response.Redirect("<script language='javascript'>alert('No record matches your criteria');</script>");
- }
- }
check.Parameters["@no_rows"].Direction = ParameterDirection.Output;
string result = check.Parameters["@no_rows"].Value.ToString();
if (result !="0")
followed by data adapter code i get
Object reference not set to an instance of an object. at run time
Plz help me out.plz guide me as to how them 'check' command can be used inside 'if' block to implement my need.
Thanking u in advance