cmd.Parameters.AddWithValue | insert record in asp.net
try
{
con.Open();
//SqlCommand cmd = new SqlCommand("insert into feesentry_tb (stud_rollno,paidfee,remain_fee)values(8,456,555)",con);
SqlCommand cmd = new SqlCommand("insert into feesentry_tb (stud_rollno,paidfee,remain_fee)values(@stud_rollno,@paidfee,@remain_fee)", con);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@stud_rollno",9);
cmd.Parameters.AddWithValue("@paidfee",233.4);
cmd.Parameters.AddWithValue("@remain_fee",4565.34);
cmd.ExecuteNonQuery();
//DataTable dt = new DataTable();
}
catch(Exception ex)
{
Response.Write(ex);
}
finally
{
con.Close();
}
try
{
con.Open();
//SqlCommand cmd = new SqlCommand("insert into feesentry_tb (stud_rollno,paidfee,remain_fee)values(8,456,555)",con);
SqlCommand cmd = new SqlCommand("insert into feesentry_tb (stud_rollno,paidfee,remain_fee)values(@stud_rollno,@paidfee,@remain_fee)", con);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@stud_rollno",9);
cmd.Parameters.AddWithValue("@paidfee",233.4);
cmd.Parameters.AddWithValue("@remain_fee",4565.34);
cmd.ExecuteNonQuery();
//DataTable dt = new DataTable();
}
catch(Exception ex)
{
Response.Write(ex);
}
finally
{
con.Close();
}
0 comments: