insert multiple data from checkboxlist to ms access RRS feed

  • Question

  • hai..
    firstly i'm sorry coz my english is not good..
    my problem is when i tick more than one at the checkboxlist,
    only one data inserted in my ms access.. anybody can help me.. this is my code..

    Imports System.Data.OleDb
    Imports System.Data

    Partial Class _Default
        Inherits System.Web.UI.Page
        Dim sSchedule As String
        Dim sqlSave As String
        Dim blData As Boolean
        Dim MySQL As String
        Dim DateItems(12, 31, 2100) As String
        Dim intMonth As Integer
        Dim intDate As Integer
        Dim intYear As Integer
        Dim sDate As String
        Dim sItem As String
        Dim DateSplit() As String
        Dim strConn As OleDbConnection
        Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
            Panel2.Visible = True
            Label4.Text = Calendar1.SelectedDate.ToShortDateString

        End Sub

        Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
            Label4.Text = Calendar1.SelectedDate.ToShortDateString
            sqlSave = "Insert into lab_booking (Name, Staff_num, Ptj, Room_no, Post, No_tel, Email, No_hp, Lab_User, Date_book, Time_book, Purpose, Soft, Komputer, LCD, Lain2) values(@calname, @calstaff, @calptj, @calroomno, @calpost, @calph, @calemel, @calhp, @callabuser, @caldate, @caltime, @calpurpose, @calsoft, @calpc, @callcd, @callain)"

            Dim Myconn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("lab.mdb") & ";")
            Dim Cmd As New OleDbCommand(sqlSave, Myconn)

            Cmd.Parameters.Add(New OleDbParameter("@calname", TextBox1.Text))
            Cmd.Parameters.Add(New OleDbParameter("@calstaff", TextBox2.Text))
            Cmd.Parameters.Add(New OleDbParameter("@calptj", DropDownList1.SelectedValue))
            Cmd.Parameters.Add(New OleDbParameter("@calroomno", TextBox4.Text))
            Cmd.Parameters.Add(New OleDbParameter("@calpost", TextBox5.Text))
            Cmd.Parameters.Add(New OleDbParameter("@calph", TextBox6.Text))
            Cmd.Parameters.Add(New OleDbParameter("@calemel", TextBox7.Text))
            Cmd.Parameters.Add(New OleDbParameter("@calhp", TextBox8.Text))
            Cmd.Parameters.Add(New OleDbParameter("@callabuser", TextBox9.Text))
            Cmd.Parameters.Add(New OleDbParameter("@caldate", Label4.Text))
            Cmd.Parameters.Add(New OleDbParameter("@caltime", DropDownList5.SelectedValue + DropDownList6.SelectedValue + DropDownList7.SelectedValue))
            Cmd.Parameters.Add(New OleDbParameter("@calpurpose", TextBox12.Text))
            Cmd.Parameters.Add(New OleDbParameter("@calsoft", CheckBoxList1.SelectedValue))
            Cmd.Parameters.Add(New OleDbParameter("@calpc", TextBox3.Text + Label3.Text))
            Cmd.Parameters.Add(New OleDbParameter("@callcd", RadioButtonList1.SelectedValue))
            Cmd.Parameters.Add(New OleDbParameter("@callain", TextBox10.Text))

            MsgBox("thank you")

            Response.Redirect("booking form.aspx")
        End Sub

    End Class
    • Moved by Vipul Patel - CLR Thursday, March 26, 2009 10:08 PM moving to a forum where this can be looked at and re-assigned. (Moved from Building Development and Diagnostic Tools for .Net to Where is the Forum For…?)
    Thursday, March 26, 2009 3:48 AM


All replies




    Thank you for your post!  Unfortunately there is not a current forum to post the question you are asking so I would recommend that you post you question to one of the microsoft.public.access.dataaccess.pages newsgroup located here:  http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.access.dataaccess.pages&cat=en_us_49310614-8070-4c88-92ae-a4070d431d86&lang=en&cr=us

    Hope that helps!

    Sudarshan shindode Tier 2 Application Support Server and Tools Online Engineering Live Services Team
    Friday, March 27, 2009 4:58 AM
  • thz sudarshans.. i'll try..
    Friday, March 27, 2009 7:08 AM
  • hello, my prob not solve yet.. i try to change the code, all data was successfully insert but, the data from checkboxlist is zero.. anybody plis help me.. this is my new code.

     Dim DB As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
                  & Server.MapPath("lab.mdb") & ";"
            Dim conn As New OleDbConnection(DB)
            Dim adapter As New OleDbDataAdapter
            Dim cb As New OleDbCommandBuilder(adapter)
            Dim sql2 As New OleDbCommand()
            'Open DB connection
            Dim SubNLetter1 As Boolean = False
            Dim SubNLetter2 As Boolean = False
            Dim SubNLetter3 As Boolean = False
            Dim SubNLetter4 As Boolean = False
            Dim SubNLetter5 As Boolean = False
            Dim SubNLetter6 As Boolean = False
            Dim SubNLetter7 As Boolean = False
            Dim SubNLetter8 As Boolean = False
            Dim SubNLetter9 As Boolean = False
            Dim SubNLetter10 As Boolean = False
            Dim SubNLetter11 As Boolean = False
            Dim SubNLetter12 As Boolean = False
            Dim SubNLetter13 As Boolean = False
            Dim SubNLetter14 As Boolean = False
            Dim SubNLetter15 As Boolean = False
            Dim SubNLetter16 As Boolean = False
            Dim SubNLetter17 As Boolean = False
            Dim SubNLetter18 As Boolean = False
            Dim SubNLetter19 As Boolean = False
            Dim SubNLetter20 As Boolean = False
            Dim SubNLetter21 As Boolean = False
            Dim SubNLetter22 As Boolean = False
            Dim SubNLetter23 As Boolean = False
            Dim SubNLetter24 As Boolean = False
            Dim SubNLetter25 As Boolean = False
            For Each LItems As ListItem In CheckBoxList1.Items
                If LItems.Selected = True Then
                    Select Case LItems.Value
                        Case "1"
                            SubNLetter1 = True
                        Case "2"
                            SubNLetter2 = True
                        Case "3"
                            SubNLetter3 = True
                        Case "4"
                            SubNLetter4 = True
                        Case "5"
                            SubNLetter5 = True
                        Case "6"
                            SubNLetter6 = True
                        Case "7"
                            SubNLetter7 = True
                        Case "8"
                            SubNLetter8 = True
                        Case "9"
                            SubNLetter9 = True
                        Case "10"
                            SubNLetter10 = True
                        Case "11"
                            SubNLetter11 = True
                        Case "12"
                            SubNLetter12 = True
                        Case "13"
                            SubNLetter13 = True
                        Case "14"
                            SubNLetter14 = True
                        Case "15"
                            SubNLetter15 = True
                        Case "16"
                            SubNLetter16 = True
                        Case "17"
                            SubNLetter17 = True
                        Case "18"
                            SubNLetter18 = True
                        Case "19"
                            SubNLetter19 = True
                        Case "20"
                            SubNLetter20 = True
                        Case "21"
                            SubNLetter21 = True
                        Case "22"
                            SubNLetter22 = True
                        Case "23"
                            SubNLetter23 = True
                        Case "24"
                            SubNLetter24 = True
                        Case "25"
                            SubNLetter25 = True
                    End Select
                End If
            'Set up the parameters
            Dim bname As New OleDbParameter("@nama", TextBox1.Text)
            Dim bstaffnum As New OleDbParameter("@pekerja", TextBox2.Text)
            Dim bptj As New OleDbParameter("@p", DropDownList1.SelectedValue)
            Dim broomno As New OleDbParameter("@bilik", TextBox4.Text)
            Dim bpost As New OleDbParameter("@jawatan", TextBox5.Text)
            Dim bphno As New OleDbParameter("@telefon", TextBox6.Text)
            Dim bemail As New OleDbParameter("@emel", TextBox7.Text)
            Dim bhpno As New OleDbParameter("@handphone", TextBox8.Text)
            Dim blabuser As New OleDbParameter("@labuser", TextBox9.Text)
            Dim bdte As New OleDbParameter("@tarikh", Label4.Text)
            Dim btime As New OleDbParameter("@masa", DropDownList5.SelectedValue + Label2.Text + DropDownList6.SelectedValue + DropDownList7.SelectedValue)
            Dim bpurpose As New OleDbParameter("@tujuan", TextBox12.Text)
            Dim bsoft As New OleDbParameter("@perisian", SubNLetter1 + SubNLetter2 + SubNLetter3 + SubNLetter4 + SubNLetter5 + SubNLetter6 + SubNLetter7 + SubNLetter8 + SubNLetter9 + SubNLetter10 + SubNLetter11 + SubNLetter12 + SubNLetter13 + SubNLetter14 + SubNLetter15 + SubNLetter16 + SubNLetter17 + SubNLetter18 + SubNLetter19 + SubNLetter20 + SubNLetter21 + SubNLetter22 + SubNLetter23 + SubNLetter24 + SubNLetter25)
            Dim bkomputer As New OleDbParameter("@pc", TextBox3.Text + Label3.Text)
            Dim blcd As New OleDbParameter("@lcd", RadioButtonList1.SelectedValue)
            Dim blain As New OleDbParameter("@lain", TextBox10.Text)
            'Set the insert command's connection
            sql2.Connection = conn
            sql2.CommandText = "INSERT INTO lab_booking ([Name], [Staff_num], [Ptj], [Room_no], [Post], [No_tel], [Email], [No_hp], [Lab_User], [Date_book], [Time_book], [Purpose], [Soft], [Komputer], [LCD], [Lain2])VALUES (@nama, @pekerja, @p, @bilik, @jawatan, @telefon, @emel, @handphone, @labuser, @tarikh, @masa, @tujuan, @perisian, @pc, @lcd, @lain)"
            adapter.InsertCommand = sql2
    Thursday, April 9, 2009 8:06 AM