helo, i have one problem..that is ..i have a one form that is user request post form..in this every thing is ok ,and successfully data was inserted but problem is .. when data inserted into db , in that age was inserted into emergency column , emergency data was inserted in age column..i am checked every thing but it is not solved ..plz help me....this is my academic project i have to create webapplication ..plz..
aspx page...
-----------------------
<%--
My Posted Events..
--%>Post Request
Requirement Details...
----
Code File data-
-------
protected void btn_post_Click(object sender, EventArgs e)
{
getid();
if (chk_emrgncy.Checked == true)
{
lbl_emr.Text = "YES";
}
else
{
lbl_emr.Text = "NO";
}
con.Open();
if (txt_recipient.Text != "" && txt_contact1.Text != "")
{
string str_insert = "insert into tbl_reqpost(pid,reqfor,quantity,bloodgroup,purpose,lastdate,country,state,district,city,recipname,age,emergency,stdcode,postalcode,contactno1,contactno2,contactperson,email,contactaddress,poston,postby)values(@pid,@reqfor,@quantity,@bloodgroup,@purpose,@lastdate,@country,@state,@district,@city,@recipname,@emergency,@age,@stdcode,@postalcode,@contactno1,@contactno2,@contactperson,@email,@contactaddress,@poston,@postby)";
SqlCommand cmdinsert = new SqlCommand(str_insert);
cmdinsert.Parameters.Add("@pid", SqlDbType.Int).Value = lbl_pid.Text;
cmdinsert.Parameters.Add("@reqfor", SqlDbType.VarChar).Value = ddl_reqfor.SelectedItem.Text;
cmdinsert.Parameters.Add("@quantity", SqlDbType.VarChar).Value = txt_quantity.Text;
cmdinsert.Parameters.Add("@bloodgroup", SqlDbType.VarChar).Value = ddl_bllodgroup.SelectedItem.Text;
cmdinsert.Parameters.Add("@purpose", SqlDbType.VarChar).Value = txt_purpose.Text;
cmdinsert.Parameters.Add("@lastdate", SqlDbType.VarChar).Value = txt_ldate.Text;
cmdinsert.Parameters.Add("@country", SqlDbType.VarChar).Value = ddl_country.SelectedItem.Text;
cmdinsert.Parameters.Add("@state", SqlDbType.VarChar).Value = ddl_state.SelectedItem.Text;
cmdinsert.Parameters.Add("@district", SqlDbType.VarChar).Value =ddl_dist.SelectedItem.Text;
cmdinsert.Parameters.Add("@city", SqlDbType.VarChar).Value = ddl_city.SelectedItem.Text;
cmdinsert.Parameters.Add("@recipname", SqlDbType.VarChar).Value = txt_recipient.Text;
cmdinsert.Parameters.Add("@age", SqlDbType.Int).Value = Convert.ToInt32(txt_reqage.Text);
cmdinsert.Parameters.Add("@emergency", SqlDbType.VarChar).Value = lbl_emr.Text;
cmdinsert.Parameters.Add("@stdcode", SqlDbType.VarChar).Value = txt_std.Text;
cmdinsert.Parameters.Add("@postalcode", SqlDbType.VarChar).Value = txt_postal.Text;
cmdinsert.Parameters.Add("@contactno1", SqlDbType.VarChar).Value = txt_contact1.Text;
cmdinsert.Parameters.Add("@contactno2", SqlDbType.VarChar).Value = txt_contact2.Text;
cmdinsert.Parameters.Add("@contactperson", SqlDbType.VarChar).Value = txt_contperson.Text;
cmdinsert.Parameters.Add("@email", SqlDbType.VarChar).Value = txt_email.Text;
cmdinsert.Parameters.Add("@contactaddress", SqlDbType.VarChar).Value = txt_faddress.Text;
cmdinsert.Parameters.Add("@poston", SqlDbType.DateTime).Value = System.DateTime.Now;
cmdinsert.Parameters.Add("@postby", SqlDbType.VarChar).Value = Session["id"].ToString();
InsertUpdateData2(cmdinsert);
Response.Write("");
}
else
{
lbl_pid.ForeColor = System.Drawing.Color.Red;
lbl_pid.Text = "Please fill required data";
}
con.Close();
}
private Boolean InsertUpdateData2(SqlCommand cmdinsert)
{
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
cmdinsert.CommandType = CommandType.Text;
cmdinsert.Connection = con;
try
{
con.Open();
cmdinsert.ExecuteNonQuery();
Response.Write("");
return true;
}
catch (Exception ex)
{
//lblMessage.Visible = true;
//lblMessage.Text = ex.Message;
Response.Write(ex.Message);
return false;
}
{
con.Close();
con.Dispose();
}
}
4 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Manas MohapatraPosted Aug 15, 2016, 6:55 AM
Vincent Maverick DuranoPosted Aug 15, 2016, 10:02 AM
eswar raoPosted Aug 15, 2016, 6:33 AM
ali tuncerPosted Aug 14, 2016, 9:21 PM
I think position of age and emergency is wrong in insert statement, you need to swap them..