Question I need some help about db + array(maybe)

StartVB

New member
Joined
Dec 12, 2009
Messages
1
Programming Experience
Beginner
If I have 2 tables
1. table_work
- workid
- workname
- income
- workercode
2. table_worker
- workerid
- workercode
- workname

I have 5 workers and 5 jobs
so I would like ask how can I click the button then program will match worker to workid which finally income will fairly distribute to 5workers

here is some code I have code already
please help me


Imports MySql.Data.MySqlClient
Imports System.Data

Public Class Form1
Dim conn As New MySqlConnection("Database=table;Data Source=localhost;User Id=root;Password=***")
Dim da As MySqlDataAdapter
Dim ds As New DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With conn
Dim conn As New MySqlConnection("Database=table;Data Source=localhost;User Id=root;Password=***")
If .State = ConnectionState.Open Then .Close()
.Open()
End With
Try
Dim strsql As String = TextBox1.Text
ds.Clear()
da = New MySqlDataAdapter(strsql, conn)
da.Fill(ds, "Mydata")
DataGridView1.DataSource = ds.Tables("Mydata")
conn.Close()

Catch ex As Exception
MessageBox.Show(ex.ToString, "error", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim fdCon As New MySqlConnection("Database=table;Data Source=localhost;User Id=root;Password=admin")
Dim fdCom As New MySqlCommand("", fdCon)
fdCon.Open()

Dim workname As String = TextBox2.Text
Dim income As String = TextBox3.Text


fdCom.CommandText = "INSERT INTO table_work (workname, income) VALUES ('" & workname & "','" & income & "')"

fdCom.ExecuteNonQuery()
fdCon.Close()
MsgBox("add already")
Button2.Enabled = True
TextBox2.Enabled = True
TextBox3.Enabled = True
Catch ex As Exception
MsgBox(ex.Message)

End Try
End Sub
End Class


thank you very much
 
Back
Top