lokiram_32
New member
- Joined
- Apr 17, 2012
- Messages
- 1
- Programming Experience
- Beginner
This is my code:
Imports MySql.Data.MySqlClient Public Class Form4 Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'RamDataSet8.subject' table. You can move, or remove it, as needed. 'Me.SubjectTableAdapter1.Fill(Me.RamDataSet8.subject) 'TODO: This line of code loads data into the 'RamDataSet7.registration' table. You can move, or remove it, as needed. Me.RegistrationTableAdapter1.Fill(Me.RamDataSet7.registration) 'TODO: This line of code loads data into the 'RamDataSet4.subject' table. You can move, or remove it, as needed. 'Me.SubjectTableAdapter.Fill(Me.RamDataSet4.subject) 'TODO: This line of code loads data into the 'RamDataSet3.course' table. You can move, or remove it, as needed. Me.CourseTableAdapter.Fill(Me.RamDataSet3.course) 'TODO: This line of code loads data into the 'RamDataSet2.registration' table. You can move, or remove it, as needed. 'Me.RegistrationTableAdapter.Fill(Me.RamDataSet2.registration) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As New MySqlConnection Dim cmd As New MySqlCommand Dim Lastname, subj_code, subj_desc, subj_unit, subj_flag As String Dim ds As New DataSet Dim da As New MySqlDataAdapter Dim i As Integer = 0 con.ConnectionString = "server=localhost;username='root';pwd='root';database=ram" con.Open() For i = 0 To DataGridView1.RowCount - 1 Lastname = DataGridView1.Item(0, i).Value.ToString subj_code = DataGridView1.Item(1, i).Value.ToString subj_desc = DataGridView1.Item(2, i).Value.ToString subj_unit = DataGridView1.Item(3, i).Value.ToString subj_flag = DataGridView1.Item(4, i).Value.ToString da.SelectCommand = cmd da.SelectCommand.Connection = con da.Fill(ds) With cmd .CommandType = CommandType.Text .CommandText = "INSERT INTO student_subject VALUES(" + addQoute(Lastname) + ", " + _ addQoute(subj_code) + ", " + _ addQoute(subj_desc) + ", " + _ addQoute(subj_unit) + ", " + _ addQoute(subj_flag) + ")" .Connection = con cmd = New MySqlCommand(.CommandText, con) End With Next If (MessageBox.Show("Do you want to continue?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes) Then cmd.ExecuteNonQuery() MessageBox.Show("Record has been saved.", "Message", MessageBoxButtons.OK) Else MessageBox.Show("Cancelled.", "Message", MessageBoxButtons.OK) End If con.Close() ComboBox1.Text = "" ComboBox2.Text = "" End Sub Public Function addQoute(ByVal str As String) As String str = Trim(str) Return "'" + str + "'" End Function Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged Dim con As New MySqlConnection con.ConnectionString = "server=localhost;username='root';pwd='root';database=ram" con.Open() Dim da As New MySqlDataAdapter("select subj_id, subj_code, subj_desc, subj_flag, subj_unit from subject where subj_id = '" & ComboBox2.SelectedValue.ToString & "'", con) Dim dt As New DataTable da.Fill(dt) Try With DataGridView1 .DataSource = dt .Columns(1).Width = 70 End With Catch ex As Exception MessageBox.Show("Error.") End Try End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Close() Form2.Show() End Sub Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged End Sub End Class
Last edited by a moderator: