Sir m using these codes to insert value to database using storeprocedure but the value is not inserting in database m not getting what is wrong..pls help thanks in advance.
m filling city and locality dropdownlist from database and inserting there id to database but not able to insert...
m getting error input type is not in correct format something like this.
Store procedure:
ALTER Procedure dbo.Post_Requirement_Buy
(
@Property_Type varchar(50),
@City_Id int,
@Locality_Id int,
@Min_Price varchar(15),
@Max_Price varchar(15),
@Bedrooms int,
@Build_up_area varchar(20),
@Key_Features varchar(100),
@Name varchar(50),
@Email varchar(50),
@Mobile_No numeric
)
as
begin
insert into tbl_post_requirement_buying
(
Property_Type,City_Id,Locality_Id,Min_Price,Max_Price,
Bedrooms,Build_up_area,Key_Features,Name,Email,Mobile_No
)
values(
@Property_Type,
@City_Id,
@Locality_Id,
@Min_Price,
@Max_Price,
@Bedrooms,
@Build_up_area,
@Key_Features,
@Name,
@Email,
@Mobile_No
)
end
code behind:
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(str);
SqlCommand cmdins = new SqlCommand("dbo.Post_Requirement_Buy", con);
cmdins.CommandType = CommandType.StoredProcedure;
cmdins.Parameters.AddWithValue("@Property_Type", ddlpropertytype.SelectedItem.Text);
cmdins.Parameters.AddWithValue("@City_Id",Convert.ToInt32(ddlcity.SelectedItem.Text));
cmdins.Parameters.AddWithValue("@Locality_Id",Convert.ToInt32(ddllocality.SelectedItem.Text));
cmdins.Parameters.AddWithValue("@Min_Price", ddlminprice.SelectedItem.Text);
cmdins.Parameters.AddWithValue("@Max_Price", ddlmaxprice.SelectedItem.Text);
cmdins.Parameters.AddWithValue("@Bedrooms", Convert.ToInt32(ddlbedrooms.SelectedItem.Text));
cmdins.Parameters.AddWithValue("@Build_up_area", txtarea.Text + ' ' + ddlarea.SelectedItem.Text);
cmdins.Parameters.AddWithValue("@Key_Features", txtfeatures.Text);
cmdins.Parameters.AddWithValue("@Name", txtname.Text);
cmdins.Parameters.AddWithValue("@Email", txtemail.Text);
cmdins.Parameters.AddWithValue("@Mobile_No", txtmobileno.Text);
con.Open();
cmdins.ExecuteNonQuery();
lblmessage.Text = "Submitted Sucessfully";
con.Close();
}
Form Design:
<table cellpadding="0" width="100%" cellspacing="20" border="0px" style="background-color: White">
<tr>
<td colspan="2">
<span style="font-size: small; font-family: Arial">Fields marked with
</span> <span style="color: #FF3300; font-size: small; font-family: Arial;">*</span><span>
style="font-size: small; font-family: Arial"> are mandatory:</span><br />
</td>
</tr>
<tr>
<td style="height: 20px" class="style4" colspan="2">
<asp:Label ID="lblmessage" runat="server" Text="" ForeColor="Green">
</td>
</tr>
<tr>
<td style="height: 52px">
</td>
<td style="height: 52px">
<span style="font-family: Arial; font-size: medium">Requirement
:</span><br />
<asp:RadioButton ID="rbtnfb" Checked="true" Text="For Buying" GroupName="radio" runat="server">
<asp:RadioButton ID="rbtnfr" Text="For Rent" GroupName="radio" runat="server">
<span style="font-size: x-small; font-family: Arial; ">
<span style="text-decoration: underline">Select Atleast One Option</span></span><br />
<%----%>
</td>
</tr>
<tr>
<td>
<span style="font-size: small; font-family: Arial">Property Type :</span><span style="color: #FF0000">* </span>
</td>
<td>
<asp:DropDownList ID="ddlpropertytype" runat="server" CssClass="validate[required] radio"
Width="270px">
<asp:ListItem Value="">--Select--
<asp:ListItem Value="Commercial">Commercial
<asp:ListItem Value="Residential">Residential
<asp:ListItem Value="Plot">Plot
<asp:ListItem Value="Bunglow">Bunglow
<asp:ListItem Value="Villa">Villa
<%----%>
</td>
</tr>
<tr>
<td>
<span style="font-size: small; font-family: Arial">City :</span><span style="color: #FF0000">* </span>
</td>
<td>
<asp:DropDownList ID="ddlcity" runat="server" Height="22px" CssClass="validate[required] radio"
Width="270px" EnableViewState="True">
<asp:ListItem Value="">--Select--
<%----%>
</td>
</tr>
<tr>
<td>
<span style="font-size: small; font-family: Arial">Locality :</span><span style="color: #FF0000">* </span>
</td>
<td>
<asp:DropDownList ID="ddllocality" runat="server" Height="22px" CssClass="validate[required] radio"
Width="270px">
<asp:ListItem Value="">--Select--
<%----%>
</td>
</tr>
<tr>
<td>
<span style="font-size: small; font-family: Arial">Price :</span><span style="color: #FF0000">* </span>
</td>
<td>
<asp:DropDownList ID="ddlminprice" runat="server" CssClass="validate[required] radio">
<asp:ListItem Value="">--Select--
<asp:ListItem Value="1">15 lacs
<asp:ListItem Value="2">20 Lacs
<asp:ListItem Value="3">30 Lacs
<asp:ListItem Value="4">40 Lacs
<asp:ListItem Value="5">50 Lacs
<asp:ListItem Value="6">60 Lacs
<asp:ListItem Value="7">70 Lacs
<asp:ListItem Value="8">80 Lacs
<asp:ListItem Value="9">90 Lacs
<asp:ListItem Value="10">1 crore
<asp:ListItem Value="11">1.2 crores
<asp:ListItem Value="12">1.4 crores
<asp:ListItem Value="13">1.6 crores
<asp:ListItem Value="14">1.8 crores
<asp:ListItem Value="15">2 crores
<asp:DropDownList ID="ddlmaxprice" runat="server" CssClass="validate[required] radio">
<asp:ListItem Value="">--Select--
<asp:ListItem Value="1">15 lacs
<asp:ListItem Value="2">20 Lacs
<asp:ListItem Value="3">30 Lacs
<asp:ListItem Value="4">40 Lacs
<asp:ListItem Value="5">50 Lacs
<asp:ListItem Value="6">60 Lacs
<asp:ListItem Value="7">70 Lacs
<asp:ListItem Value="8">80 Lacs
<asp:ListItem Value="9">90 Lacs
<asp:ListItem Value="10">1 crore
<asp:ListItem Value="11">1.2 crores
<asp:ListItem Value="12">1.4 crores
<asp:ListItem Value="13">1.6 crores
<asp:ListItem Value="14">1.8 crores
<asp:ListItem Value="15">2 crores
</td>
</tr>
<tr>
<td>
<span style="font-size: small; font-family: Arial">Bedrooms :
</span></td>
<td>
<asp:DropDownList ID="ddlbedrooms" runat="server"
Width="270px">
<asp:ListItem Value="">--Select--
<asp:ListItem Value="1">0
<asp:ListItem Value="2">1
<asp:ListItem Value="3">2
<asp:ListItem Value="4">3
<asp:ListItem Value="5">4
<asp:ListItem Value="6">5
<asp:ListItem Value="7">6
<asp:ListItem Value="8">7
<asp:ListItem Value="9">8
<asp:ListItem Value="10">9
<asp:ListItem Value="11">10
<%----%>
</td>
</tr>
<tr>
<td>
<span style="font-size: small; font-family: Arial">Built Up Area :</span><span style="color: #FF0000">* </span>
</td>
<td>
<asp:TextBox ID="txtarea" runat="server" CssClass="validate[required,custom[number]]"
Width="134px">
<asp:DropDownList ID="ddlarea" runat="server" CssClass="validate[required] radio">
<asp:ListItem Value="">--Select--
<asp:ListItem Value="fe">sqft
<asp:ListItem Value="me">sqm
<asp:ListItem Value="ya">sqyds
</td>
</tr>
<tr>
<td valign="top">
<span style="font-size: small; font-family: Arial">Key Features :</span>
</td>
<td>
<asp:TextBox ID="txtfeatures" runat="server" Height="83px" TextMode="MultiLine" Width="270px">
</td>
</tr>
<tr>
<td>
<span style="font-size: small; font-family: Arial">Your Name :</span><span style="color: #FF0000">* </span>
</td>
<td>
<asp:TextBox ID="txtname" runat="server" CssClass="validate[required,custom[onlyLetterSp]]"
Width="270px">
<%----%>
</td>
</tr>
<tr>
<td>
<span style="font-size: small; font-family: Arial">Your Email :</span><span style="color: #FF0000">* </span>
</td>
<td>
<asp:TextBox ID="txtemail" runat="server" CssClass="validate[required,custom[email]"
Width="270px">
<%----%>
</td>
</tr>
<tr>
<td>
<span style="font-size: small; font-family: Arial">Mobile No :</span><span style="color: #FF0000">* </span>
</td>
<td>
<asp:TextBox ID="txtmobileno" runat="server" CssClass="validate[required,custom[onlyNumberSp]]"
Width="270px">
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button class="btn" ID="btnSubmit" runat="server" Text="Submit" Width="87px"
onclick="btnSubmit_Click" />
<asp:Button class="btn" ID="btnreset" runat="server" type="reset" UseSubmitBehavior="false"
Text="Reset" Width="87px" onclick="btnreset_Click"/>
</td>
</tr>
<tr>
<td colspan="2">
<%----%>
</td>
</tr>
</table>
database Design:
create table tbl_post_requirement_buying
(
Req_ID int identity(1,1)primary key,
Property_Type varchar(50)not null,
City_Id int references tbl_City(City_Id) not null,
Locality_Id int references tbl_Locality(Locality_Id)not null,
Min_Price varchar(15) not null,
Max_Price varchar(15) not null,
Bedrooms int null,
Build_up_area varchar(20) not null,
Key_Features varchar(100)null,
Name varchar(50)not null,
Email varchar(50)not null,
Mobile_No numeric not null
)