Hello friend, as per my understanding of this problem, you have to do the following changes:
First of all make the stored procedure parametric, means you have to add parameters so that you can pass the values from your code behind:
ALTER procedure [dbo].[PreseaFac]
@Facid varchar(50),
@Facname varchar(50),
@FacQ1 varchar(50),
@FacQ2 varchar(50),
@FacQ3 varchar(50),
@FacQ4 varchar(50),
@FacQ5 varchar(50)
AS
BEGIN
INSERT INTO Tb_Faculty_Feedback
(Facid ,Facname, FacQ1, FacQ2, FacQ3, FacQ4, FacQ5)
VALUES (@Fid,@Facid,@FacQ1,@FacQ2,@FacQ3,@FacQ4,@FacQ5)
END
I assume you must have added controls on your aspx page as follows:
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="1">Poor</asp:ListItem>
<asp:ListItem Value="2">Fair</asp:ListItem>
<asp:ListItem Value="3">Good</asp:ListItem>
<asp:ListItem Value="4">Very Good</asp:ListItem>
<asp:ListItem Value="5">Excellent</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem Value="1">Poor</asp:ListItem>
<asp:ListItem Value="2">Fair</asp:ListItem>
<asp:ListItem Value="3">Good</asp:ListItem>
<asp:ListItem Value="4">Very Good</asp:ListItem>
<asp:ListItem Value="5">Excellent</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server">
<asp:ListItem Value="1">Poor</asp:ListItem>
<asp:ListItem Value="2">Fair</asp:ListItem>
<asp:ListItem Value="3">Good</asp:ListItem>
<asp:ListItem Value="4">Very Good</asp:ListItem>
<asp:ListItem Value="5">Excellent</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList4" runat="server">
<asp:ListItem Value="1">Poor</asp:ListItem>
<asp:ListItem Value="2">Fair</asp:ListItem>
<asp:ListItem Value="3">Good</asp:ListItem>
<asp:ListItem Value="4">Very Good</asp:ListItem>
<asp:ListItem Value="5">Excellent</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList5" runat="server">
<asp:ListItem Value="1">Poor</asp:ListItem>
<asp:ListItem Value="2">Fair</asp:ListItem>
<asp:ListItem Value="3">Good</asp:ListItem>
<asp:ListItem Value="4">Very Good</asp:ListItem>
<asp:ListItem Value="5">Excellent</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
Then you have to write ADO.NET code to call this stored procedure from the Submit button click as follows:
string conStr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(conStr))
{
con.Open();
SqlParameter Facid = new SqlParameter();
Facid.ParameterName = "@Facid";
Facid.Value = "1";
SqlParameter Facname = new SqlParameter();
Facname.ParameterName = "@Facname";
Facname.Value = "DD";
SqlParameter FacQ1 = new SqlParameter();
FacQ1.ParameterName = "@FacQ1";
FacQ1.Value = DropDownList1.SelectedValue;
SqlParameter FacQ2 = new SqlParameter();
FacQ2.ParameterName = "@FacQ2";
FacQ2.Value = DropDownList2.SelectedValue;
SqlParameter FacQ3 = new SqlParameter();
FacQ3.ParameterName = "@FacQ3";
FacQ3.Value = DropDownList3.SelectedValue;
SqlParameter FacQ4 = new SqlParameter();
FacQ4.ParameterName = "@FacQ4";
FacQ4.Value = DropDownList4.SelectedValue;
SqlParameter FacQ5 = new SqlParameter();
FacQ5.ParameterName = "@FacQ5";
FacQ5.Value = DropDownList5.SelectedValue;
SqlCommand cmd = new SqlCommand("PreseaFac", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(Facid);
cmd.Parameters.Add(Facname);
cmd.Parameters.Add(FacQ1);
cmd.Parameters.Add(FacQ2);
cmd.Parameters.Add(FacQ3);
cmd.Parameters.Add(FacQ4);
cmd.Parameters.Add(FacQ5);
cmd.ExecuteNonQuery();
}
Note: I have kept your database changes intact. Please make sure that you implement some exception handling as well.
- DD