Can't say much.
Have a db named test, a table named activity with fields ActivityID and Activities
Got a form with one textbox named txtactivity. Visible property set to false.
got a label with text Activities.
Got Six checkboxes with six different options.
And of course a button
Code works but needs some extra touch. If you can make it shoter, tha'll be cool.
Imports System.Data.SqlClient
Public Class Form1
'path variable use for Get application running path
Dim path As String = (Microsoft.VisualBasic.Left(Application.StartupPath, Len(Application.StartupPath) - 9))
Dim con As New SqlConnection("Data Source=localhost;Initial Catalog=test;Integrated Security=True")
Dim cmd As SqlCommand
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = False And CheckBox2.Checked = False And CheckBox3.Checked = False And CheckBox4.Checked = False And CheckBox5.Checked = False And CheckBox6.Checked = False Then
MsgBox("Please select atleast one activity")
Else
If CheckBox1.Checked Then
CheckBox1.Text = CheckBox1.Text
Else : CheckBox1.Text = ""
End If
If CheckBox2.Checked = True Then
CheckBox2.Text = CheckBox2.Text
Else : CheckBox2.Text = ""
End If
If CheckBox3.Checked = True Then
CheckBox3.Text = CheckBox3.Text
Else : CheckBox3.Text = ""
End If
If CheckBox4.Checked = True Then
CheckBox4.Text = CheckBox4.Text
Else : CheckBox4.Text = ""
End If
If CheckBox5.Checked = True Then
CheckBox5.Text = CheckBox5.Text
Else : CheckBox5.Text = ""
End If
If CheckBox6.Checked = True Then
CheckBox6.Text = CheckBox6.Text
Else : CheckBox6.Text = ""
End If
txtactivity.Text = CheckBox1.Text + " " + CheckBox2.Text + " " + CheckBox3.Text + " " + CheckBox4.Text + " " + CheckBox5.Text + " " + CheckBox6.Text
Dim sql As String = "INSERT INTO Activity VALUES(@Activities)"
Dim cmd As New SqlCommand(sql, con)
cmd.Parameters.AddWithValue("@Activities", txtactivity.Text)
cmd.ExecuteNonQuery()
MessageBox.Show("Information has been saved", "Save", MessageBoxButtons.OK)
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con.Open()
End Sub
End Class