Imports System.Data.SqlClient Imports System.Text Public Class Form5 Dim cn As New SqlConnection("Data Source=NIDA-PC\SQLEXPRESS;Initial Catalog=Exami_Data;Integrated Security=True") Dim da As New SqlDataAdapter() Dim ds As New DataSet Dim dr As SqlDataReader Dim qry As String Dim qry1 As String 'Dim qry2 As String Dim dt As New DataTable Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load qry1 = "Select empl_ID from employees where User_Type='Instructor'" da = New SqlDataAdapter(qry1, cn) ds = New DataSet() da.Fill(ds, "tab") ComboBox1.DataSource = ds.Tables("tab") ComboBox1.DisplayMember = "empl_ID" ComboBox1.ValueMember = "empl_ID" ComboBox1.Text = "" qry = "Select Module_ID,Module_Name from Modules" da = New SqlDataAdapter(qry, cn) ds = New DataSet() da.Fill(ds, "tab") CheckedListBox1.DataSource = ds.Tables("tab") CheckedListBox1.DisplayMember = "Module_Name" CheckedListBox1.ValueMember = "Module_ID" CheckedListBox1.Text = "" End Sub Public Sub Stringbuilder() Dim item As Object cn.Open() For Each item In CheckedListBox1.CheckedItems Dim cmd As New SqlCommand cmd.CommandText = "insert into Assign_Modules(empl_ID,Module_ID) values(" & ComboBox1.GetItemText(ComboBox1.SelectedItem.ToString) & "," & item(0).ToString & ")" cmd.Connection = cn Dim rowsInserted = cmd.ExecuteNonQuery() MsgBox("inserted " & rowsInserted & "rows", MsgBoxStyle.OkOnly) Next cn.Close() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Stringbuilder() End Sub End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)