I am inserting data into database, then retrieving into GridView, I have DropDownList in which i given value (1,2,3,4,5,6,7,8,9) and it is outside of GridView.
Now i want, when i insert record into database, before inserting data into data base, it checks which value is exit in DropDownList.
If value is 5, if user inserting more than five rows then record should not save.
C#
protected void btn_in_Click(object sender, EventArgs e)
{
Updatebal();
}
private void Updatebal()
{
if (txtupbalno.Text == "")
{
Response.Write("<script language='javascript'>alert('Please Insert Bale ');</script>");
}
else if (DDLPktype.SelectedValue == Label2.Text)
{
Response.Write("<script language='javascript'>alert('Please Check Pack Type');</script>");
}
else if (txtOrder.Text != txtuporder.Text)
{
Response.Write("<script language='javascript'>alert('Please Check Orderno');</script>");
}
else if (txtupdqty.Text != "1")
{
Response.Write("<script language='javascript'>alert('Please Check QTY');</script>");
}
else
{
using (SqlCommand cmd = new SqlCommand("insert into tbl_PckDetail (Prdno,Codeitem,PID,Orderno,QTY,EDate,ETime,IPAddress) values (@Prdno,@Codeitem,@PID,@Orderno,@QTY,@EDate,@ETime,@IPAddress)", con))
using (SqlCommand cmdu = new SqlCommand("UPDATE Probale SET PID = @PID WHERE Prdno = @Prdno", con))
{
cmd.Parameters.AddWithValue("@Prdno", txtupbalno.Text);
cmd.Parameters.AddWithValue("@Codeitem", DDLupditem.SelectedValue);
cmd.Parameters.AddWithValue("@PID", txtpackno.Text);
cmd.Parameters.AddWithValue("@Orderno", txtuporder.Text);
cmd.Parameters.AddWithValue("@QTY", txtupdqty.Text);
cmd.Parameters.AddWithValue("@EDate", DateTime.Now.ToString());
cmd.Parameters.AddWithValue("@ETime", DateTime.Now.ToString("hh:mm"));
cmd.Parameters.AddWithValue("@IPAddress", lblIP.Text);
cmdu.Parameters.AddWithValue("@Prdno", txtupbalno.Text);
cmdu.Parameters.AddWithValue("@PID", txtpackno.Text);
cmd.Connection = con;
cmdu.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
cmdu.ExecuteNonQuery();
con.Close();
searchPakno();
}
}
clear1();
}