I have a webform project in asp .net with c# and in my sql query I need data that the user is going to provide.
The week field is entered in a textbox in webform1 and I have the query in webform2. According to that data, it will show me certain records in a gridview. In addition to the login cod_user. Next I show the code
Mistakes:
*'Value cannot be null. Parameter name: String' of the line: int value = Int32.Parse(Request.QueryString["week"]);
*'The query with parameters '(@cod varchar(5))SELECT blah blah' expects the parameter '@cod', which was not supplied.'
ORIGIN PAGE
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");
}
}
DESTINATION PAGE
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
Cheers
Thank you
Let's go by parts, verify that you have data with the following lines of code
Update
For the Cod_User, replace:
By:
For the week:
Replaces:
By: