Reputation: 13
I have two stored procedures:
Each procedure returns a different table. I have only one user input parameter TN
. This parameter I'm reading from search txt line (inputTNReturn.Value
)
Each procedure posts data in a different grid view
This code returns only LAST stored procedure to last gridView
I don't have any idea where is my mistake and why I can get 2 grid view from 2 procedure.
I'll appreciate for any help
protected void btnSearch_Click(object sender, EventArgs e)
{
string connectionStr = ConfigurationManager
.ConnectionStrings["ConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(connectionStr))
{
con.Open();
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "[spRO_Status_OrderInfo]";
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "spRO_Status_Change";
cmd.CommandType = CommandType.StoredProcedure;
if (inputTNReturn.Value.Trim() != "")
{
SqlParameter param = new SqlParameter("@TN", inputTNReturn.Value);
cmd.Parameters.Add(param);
SqlDataReader rdr = cmd.ExecuteReader();
gvSearchResults.DataSource = rdr;
gvSearchResults.DataBind();
GridView1.DataSource = rdr;
GridView1.DataBind();
lblinputTNReturn.Text = inputTNReturn.Value;
}
}
if (inputTNReturn.Value == "")
{
inputTNReturn.Value = "Please add tracking number";
}
con.Close();
}
}
Upvotes: 0
Views: 585
Reputation: 11
Here is where you're setting the first stored procedure
cmd.CommandText = "[spRO_Status_OrderInfo]";
cmd.CommandType = CommandType.StoredProcedure;
Here is where you're overwriting the above
cmd.CommandText = "spRO_Status_Change";
cmd.CommandType = CommandType.StoredProcedure;
You're not adding a second command text / type, you're just over writing the first one which is why you're only seeing the second one come out in the output.
Upvotes: 1