I have a webform project in asp .net with c # and in my query sql I need data that the user will provide.
The week field is entered in a textbox in the webform1 and the query is in the webform2. According to that data, it will show me certain records in a gridview. In addition to the session start cod_user. Below I show the code
Errors:
* 'The value can not be null. Parameter name: String 'of the line: int value = Int32.Parse (Request.QueryString ["week"]);
* 'Query with parameters' (@cod varchar (5)) SELECT blah bla 'awaits the parameter' @cod ', which has not been provided.'
PAGE ORIGIN
protected void BUTTON1_Click(object sender, EventArgs e)
{
string semana = sem.Text;
if (sem.Text != null)
{
Response.Redirect("webform2.aspx?semana=" + semana);
}
else {
Response.Redirect("webform1.aspx");
}
}
PAGE DESTINY
protectedvoid Page_Load(object sender, EventArgs e)
{
int valor = Int32.Parse(Request.QueryString["semana"]);// valor que viene de otro webform
SqlConnection con = newSqlConnection(ConfigurationManager.ConnectionStrings["cn"].ToString());
con.Open();
SqlCommand cmd = newSqlCommand("SELECT WHERE(Sem.Semana = '@sem') AND(Cab.Cod_user= '@cod') AND(etc...", con);
cmd.Parameters.Add("@sem", SqlDbType.TinyInt, 3);
cmd.Parameters["@sem"].Value = valor;
cmd.Parameters.Add("@cod", SqlDbType.VarChar, 5);
cmd.Parameters["@cod"].Value = Session["Cod_user"];
SqlDataAdapter da = newSqlDataAdapter(cmd);
DataTable dt = newDataTable();
da.Fill(dt);
gridview1.Visible = true;
gridview1.DataSource = dt;
gridview.DataBind();
con.Close();
}
I hope you can help me
Greetings
Thanks