TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
eswar rao
1.6k
98
19.3k
why data was not inserted properly in asp.net(webapp)
Aug 14 2016 11:25 AM
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...
-----------------------
<asp:Content ID="Content2" runat="server" contentplaceholderid="ContentPlaceHolder1">
<div>
<div class="row">
<!-- page header -->
<div class="col-lg-12">
<%-- <h3 class="c_title">My Posted Events..</h3>--%>
<h3 class="page-header c_title">Post Request</h3>
</div>
<!--end page header -->
</div>
<div class="row">
<div class="col-lg-9 col-lg-offset-1">
<!-- Form Elements -->
<div class="panel panel-default">
<div class="panel-heading">
Requirement Details...
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-12">
<div class="form-group col-sm-6">
<label>Country *</label>
<asp:DropDownList ID="ddl_country" CssClass="form-control" TabIndex="1" AppendDataBoundItems="true" Font-Bold="true" AutoPostBack="true" ForeColor="#009933" runat="server" OnSelectedIndexChanged="ddl_country_SelectedIndexChanged">
<asp:ListItem>-- Select Country --</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" InitialValue="--Select Country--" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="ddl_country" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<div class="form-group col-sm-6">
<label>State *</label>
<asp:DropDownList ID="ddl_state" CssClass="form-control" TabIndex="2" AppendDataBoundItems="true" Font-Bold="true" AutoPostBack="true" ForeColor="#009933" runat="server" OnSelectedIndexChanged="ddl_state_SelectedIndexChanged">
<asp:ListItem>-- Select State --</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" InitialValue="--Select State--" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="ddl_state" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<div class="form-group col-sm-6">
<label>District *</label>
<asp:DropDownList ID="ddl_dist" CssClass="form-control" TabIndex="3" Font-Bold="true" ForeColor="#009933" runat="server">
<asp:ListItem>-- Select District --</asp:ListItem>
</asp:DropDownList>
</div>
<div class="form-group col-sm-6">
<label>City *</label>
<asp:DropDownList ID="ddl_city" AppendDataBoundItems="true" TabIndex="4" CssClass="form-control" Font-Bold="true" ForeColor="#009933" runat="server">
<asp:ListItem>--Select City--</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" InitialValue="--Select City--" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="ddl_city" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<div class="form-group col-sm-12">
<label>Request For *</label>
<asp:DropDownList ID="ddl_reqfor" CssClass="form-control" TabIndex="5" ForeColor="#009933" Font-Bold="true" runat="server">
<asp:ListItem>-- Request For --</asp:ListItem>
<asp:ListItem>FOOD</asp:ListItem>
<asp:ListItem>BLOOD</asp:ListItem>
<asp:ListItem>MONEY</asp:ListItem>
<asp:ListItem>ORGAN</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" InitialValue="-- Request For --" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="ddl_reqfor" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<div class="form-group col-sm-6">
<label>Quantity *</label>
<asp:TextBox ID="txt_quantity" runat="server" ForeColor="#009933" Font-Bold="true" TabIndex="6" CssClass="form-control" placeholder="Enter required quantity"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="txt_quantity" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<div class="form-group col-sm-6">
<label>Age *</label>
<asp:TextBox ID="txt_reqage" runat="server" ForeColor="#009933" Font-Bold="true" TabIndex="7" CssClass="form-control" placeholder="Enter Age"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="txt_reqage" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<div class="form-group col-sm-6">
<label>Blood Group *</label>
<asp:DropDownList ID="ddl_bllodgroup" CssClass="form-control" TabIndex="8" Font-Bold="true" ForeColor="#009933" runat="server">
<asp:ListItem>-- Select Blood Group --</asp:ListItem>
<asp:ListItem>A +ve</asp:ListItem>
<asp:ListItem>A -ve</asp:ListItem>
<asp:ListItem>A1 +ve</asp:ListItem>
<asp:ListItem>A1 -ve</asp:ListItem>
<asp:ListItem>A1B +ve</asp:ListItem>
<asp:ListItem>A1B -ve</asp:ListItem>
<asp:ListItem>A2 +ve</asp:ListItem>
<asp:ListItem>A2 -ve</asp:ListItem>
<asp:ListItem>A2B +ve</asp:ListItem>
<asp:ListItem>A2B -ve</asp:ListItem>
<asp:ListItem>AB +ve</asp:ListItem>
<asp:ListItem>AB -ve</asp:ListItem>
<asp:ListItem>B +ve</asp:ListItem>
<asp:ListItem>B -ve</asp:ListItem>
<asp:ListItem>O +ve</asp:ListItem>
<asp:ListItem>O -ve</asp:ListItem>
<asp:ListItem>Bombay Blood Group</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" InitialValue="-- Select Blood Group --" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="ddl_bllodgroup" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<div class="form-group col-sm-6">
<label>Purpose *</label>
<asp:TextBox ID="txt_purpose" runat="server" ForeColor="#009933" Font-Bold="true" TabIndex="9" CssClass="form-control" placeholder="For which purpose"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="txt_purpose" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<div class="form-group col-sm-12">
<label>Last Date of Requirement *</label>
<asp:TextBox ID="txt_ldate" runat="server" ForeColor="#009933" Font-Bold="true" TabIndex="10" TextMode="Date" CssClass="form-control" placeholder="For which purpose"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="txt_ldate" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<div class="form-group col-sm-12">
<label> Recipient Name *</label>
<asp:TextBox ID="txt_recipient" runat="server" ForeColor="#009933" Font-Bold="true" TabIndex="11" CssClass="form-control" placeholder="Recipient Name"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="txt_recipient" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<div class="form-group well col-sm-12 ">
<label >Emergency Requirement </label><br />
<asp:CheckBox ID="chk_emrgncy" runat="server" Text="Yes" ForeColor="#009933" TabIndex="12" Font-Bold="true" />
</div>
<div class="form-group col-sm-6">
<label>STD Code </label>
<asp:TextBox ID="txt_std" runat="server" CssClass="form-control" ForeColor="#009933" TabIndex="13" Font-Bold="true" placeholder="Enter STD Code"></asp:TextBox>
</div>
<div class="form-group col-sm-6">
<label>Postal Code </label>
<asp:TextBox ID="txt_postal" runat="server" CssClass="form-control" ForeColor="#009933" TabIndex="14" Font-Bold="true" placeholder="Enter Postal Code"></asp:TextBox>
</div>
<div class="form-group col-sm-6">
<label>Contact No 1 *</label>
<asp:TextBox ID="txt_contact1" runat="server" CssClass="form-control" ForeColor="#009933" TabIndex="15" Font-Bold="true" placeholder="Enter Contact 1"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="txt_contact1" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<div class="form-group col-sm-6">
<label>Contact No 2 </label>
<asp:TextBox ID="txt_contact2" runat="server" CssClass="form-control" ForeColor="#009933" TabIndex="16" Font-Bold="true" placeholder="Enter Contact 2"></asp:TextBox>
</div>
<div class="form-group col-sm-6">
<label>Contact Person *</label>
<asp:TextBox ID="txt_contperson" runat="server" CssClass="form-control" ForeColor="#009933" TabIndex="17" Font-Bold="true" placeholder="Contact Person Name"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="txt_contperson" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<div class="form-group col-sm-6">
<label>Email </label>
<asp:TextBox ID="txt_email" runat="server" CssClass="form-control" TextMode="Email" TabIndex="18" ForeColor="#009933" Font-Bold="true" placeholder="Enter email"></asp:TextBox>
</div>
<div class="form-group col-sm-12">
<label>Contact Address *</label>
<asp:TextBox ID="txt_faddress" runat="server" TextMode="MultiLine" ForeColor="#009933" TabIndex="19" Height="100px" CssClass="form-control" placeholder="Enter Contact Address"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" CssClass="text-danger" Display="Dynamic" ControlToValidate="txt_faddress" ValidationGroup="reqp" ErrorMessage="Required this field.."></asp:RequiredFieldValidator>
</div>
<asp:Button ID="btn_post" runat="server" CssClass="btn btn-success" ValidationGroup="reqp" TabIndex="20" Text="Post Request" OnClick="btn_post_Click" />
<asp:Button ID="btn_clear" runat="server" CssClass="btn btn-danger" Text="Clear.." />
<asp:Label ID="lbl_pid" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:Label ID="lbl_emr" Visible="false" runat="server" Text="Label"></asp:Label>
</div>
</div>
</div>
</div>
<!-- End Form Elements -->
</div>
</div>
</div>
</asp:Content>
----
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("<script>alert('Successfully Post Request..!!')</script>");
}
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("<script>alert('Successfully Post Request..!!')</script>");
return true;
}
catch (Exception ex)
{
//lblMessage.Visible = true;
//lblMessage.Text = ex.Message;
Response.Write(ex.Message);
return false;
}
{
con.Close();
con.Dispose();
}
}
Reply
Answers (
4
)
CS0103: The name 'url' does not exist in the current contex
How to keep the page contents if it is posted back