i want fetch data on gridview if status is sucess
protected void searchid_Click(object sender, EventArgs e) { Grd_Search_Fill(); }
private void Grd_Search_Fill() {
try { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["name"].ConnectionString);
SqlCommand cmd = new SqlCommand("sp_name", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", txt_id.Text);
cmd.Parameters.Add("@Status", SqlDbType.VarChar, 50); cmd.Parameters["@Status"].Direction = ParameterDirection.Output;
con.Open(); cmd.ExecuteNonQuery();
string msg = cmd.Parameters["@Status"].Value.ToString(); if (msg == "sucess") { artilcepdf(); } else { lblstatus.Text = msg;
}
} catch (Exception ex) { ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Oops!! following error occured : " + ex.Message.ToString() + "');", true);
} }
public void artilcepdf() { try { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "sp_2";
DataTable dt = exex.GetRecords(cmd, "name"); if (dt.Rows.Count > 0) { gvComplete.DataSource = dt; gvComplete.DataBind(); gvComplete.UseAccessibleHeader = true; gvComplete.HeaderRow.TableSection = TableRowSection.TableHeader; gvComplete.FooterRow.TableSection = TableRowSection.TableFooter; } else { gvComplete.DataSource = null; gvComplete.DataBind(); }
} catch (Exception ex) {
string ErrorMessage = string.Empty; string ErrorTrace = string.Empty;
ErrorMessage = ex.Message; ErrorTrace = ex.StackTrace;
Stored procedure
PROCEDURE [dbo].[sp_name] @ID VARCHAR(50), @Status VARCHAR(50) = 'sucess' OUTPUT AS BEGIN set @Status = 'sucess' IF NOT EXISTS ( SELECT CaseID FROM table WHERE CaseID = @ID ) BEGIN SET @Status = 'ID Invalid' END ELSE IF EXISTS ( SELECT RefNo AS total FROM tablename WHERE CaseID = @ID AND ( columname= 'N' OR columname IS NULL ) ) BEGIN SET @Status = 'All not opened' END
ELSE IF EXISTS ( SELECT ano FROM table2name WHERE CaseID = @ID AND Is = 'Y' ) BEGIN SET @Status = 'under ' END
else IF EXISTS ( SELECT ArtNo FROM [dbo].[table3name] WHERE CaseID = @ID AND (STATUS is null or STATUS <>'ds' )) BEGIN SET @Status = 'Under' END
ELSE IF EXISTS ( SELECT pid FROM table4name WHERE CaseID =@ID GROUP BY pid HAVING (count(pid ) <> max(noart)) ) BEGIN SET @Status = 'All ' END END
PROCEDURE [dbo].[sp_2] @ID Varchar(150)='' AS BEGIN SELECT ANo ,CID ,Sno FROM [dbo].[tablename] WHERE ID= @ID END