mardi 24 janvier 2017

many checkbox list not save in database

i do some code to save data and i do code for checkboxlist to save it in data it's work with only one checkbox when i choose two checkbox it's just save the first one

like this

page

database

asp.net code

<table style="height: 172px; margin-top: 15px;margin-top:10px;">
                            <tr><td colspan="5" class="auto-style5" style="padding-left:250px; font-size:29px"><strong>Faculty Members</strong></td></tr>
            <tr><td class="auto-style4" style="width: 171px; font-size:20px">Frist Name:</td><td class="auto-style1">
                <asp:TextBox ID="txt_fname" runat="server" style="width: 171px"></asp:TextBox>
                </td><td class="auto-style4" style="width: 108px; font-size:20px; padding-left:20px;">Last Name:</td><td class="auto-style1">
                <asp:TextBox ID="txt_lname" runat="server" style="width: 171px"></asp:TextBox>
                </td></tr>
            <tr><td class="auto-style4" style="height: 34px; width: 171px; font-size:20px">Specialization:</td><td class="auto-style1" style="height: 34px">
                <asp:TextBox ID="TextBox1" runat="server" style="width: 171px"></asp:TextBox>
                </td><td class="auto-style4" style="height: 34px; width: 108px; font-size:20px; padding-left:20px;">Degee:</td><td class="auto-style1" style="height: 34px">
                <asp:TextBox ID="txt_degree" runat="server" style="width: 171px"></asp:TextBox>
                </td></tr>
            <tr><td class="auto-style4" style="width: 171px; font-size:20px">Addrss:</td><td class="auto-style1">
                <asp:TextBox ID="txt_address" runat="server" style="width: 171px"></asp:TextBox>
                </td><td class="auto-style4" style="width: 128px; font-size:20px; padding-left:20px;">PhoneNumber:</td><td class="auto-style1">
                <asp:TextBox ID="txt_phone" runat="server" style="width: 171px"></asp:TextBox>
                </td></tr>
    <tr><td class="auto-style4" style="width: 171px; font-

[size:20px">Subject_ID:</td><td class="auto-style1">
<asp:CheckBoxList ID="CheckBoxList1" runat="server"><asp:ListItem>DataBases</asp:ListItem>
    <asp:ListItem>Programming 1</asp:ListItem>
    <asp:ListItem>programming 2</asp:ListItem>
</asp:CheckBoxList>


</td></tr>
                <tr><td class="auto-style4" style="width: 291px; font-size:20px">Faculty Members Number:</td><td class="auto-style1">
                    <asp:TextBox ID="txt_Snumber" runat="server" style="width: 171px"></asp:TextBox>
                    </td><td colspan="2"  class="auto-style4" style="width: 108px; padding-left:50px">
                        <asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click" />
                    </td></tr>
        <tr><td colspan="4" style="text-align:center"><asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label></td></tr>


            </table>][1]

c# code

public partial class admins : System.Web.UI.Page
{

SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-677TN4G\SQLEXPRESS;Initial Catalog=homework;Persist Security Info=True;User ID=sa;Password=123456");

protected void Page_Load(object sender, EventArgs e)
{
    con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{


    SqlCommand cmd = new SqlCommand("insert into Staff values('" + txt_fname.Text + "','" + txt_lname.Text + "','" + txt_Snumber.Text + "','" + txt_degree.Text + "','" + txt_address.Text + "','" + txt_phone.Text + "','" + CheckBoxList1.SelectedValue + "','" + txt_Snumber.Text + "')", con);
    cmd.ExecuteNonQuery();
    con.Close();
    Label1.Visible = true;
    Label1.Text = "Data is Saved";
    txt_Snumber.Text = "";
    txt_fname.Text = "";
    txt_lname.Text = "";
    txt_address.Text = "";
    txt_degree.Text = "";
    txt_phone.Text = "";
    txt_Snumber.Text = "";


   }
}




Aucun commentaire:

Enregistrer un commentaire