没写完vb加MySQL

Imports MySql.Data.MySqlClient


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim tc As TabControl = New TabControl()
        Dim tp1 As TabPage = New TabPage("患者列表")
        Dim tp2 As TabPage = New TabPage("病历")
        Dim dgv As DataGridView = New DataGridView()
        AddHandler dgv.CellEndEdit, AddressOf dgvCEE

        tc.Dock = DockStyle.Fill
        dgv.Dock = DockStyle.Fill
        dgv.DataSource = selectAll()


        Me.Size = New Point(1900, 1000)
        Me.WindowState = FormWindowState.Maximized

        tc.Controls.Add(tp1)
        tc.Controls.Add(tp2)
        tp1.Controls.Add(dgv)

        Me.Controls.Add(tc)
        dgv.Columns(0).ReadOnly = True
    End Sub

    Private Function updateRow(ByVal rowid As String, ByVal username As String, ByVal gender As String, ByVal birthday As String, ByVal mobile1 As String, ByVal guomin As String, ByVal jiwangbingshi As String, ByVal doctor As String, ByVal zhusu As String, ByVal zhiliao As String, ByVal beizhu As String) As Integer
        Dim i As Integer = 0
        Using con As MySqlConnection = New MySqlConnection("Server=127.0.0.1;Database=mydata;Uid=root;Pwd=;CharSet=gbk;")
            Using cmd As MySqlCommand = New MySqlCommand("update t_user set username = @username, gender = @gender, birthday = @birthday, mobile1 = @mobile1, guomin = @guomin, jiwangbingshi = @jiwangbingshi, doctor = @doctor, zhusu = @zhusu, zhiliao = @zhiliao, beizhu = @beizhu where rowid = @rowid", con)
                cmd.Parameters.AddWithValue("rowid", rowid)
                cmd.Parameters.AddWithValue("username", username)
                cmd.Parameters.AddWithValue("gender", gender)
                cmd.Parameters.AddWithValue("birthday", birthday)
                cmd.Parameters.AddWithValue("mobile1", mobile1)
                cmd.Parameters.AddWithValue("guomin", guomin)
                cmd.Parameters.AddWithValue("jiwangbingshi", jiwangbingshi)
                cmd.Parameters.AddWithValue("doctor", doctor)
                cmd.Parameters.AddWithValue("zhusu", zhusu)
                cmd.Parameters.AddWithValue("zhiliao", zhiliao)
                cmd.Parameters.AddWithValue("beizhu", beizhu)
                con.Open()
                i = cmd.ExecuteNonQuery()
            End Using
        End Using
        Return i
    End Function

    Private Sub dgvCEE(ByVal sender As Object, ByVal dgvcea As DataGridViewCellEventArgs)
        Dim rowid As String = CType(sender, DataGridView).Rows(dgvcea.RowIndex).Cells(0).Value
        Dim username As String = CType(sender, DataGridView).Rows(dgvcea.RowIndex).Cells(1).Value
        Dim gender As String = CType(sender, DataGridView).Rows(dgvcea.RowIndex).Cells(2).Value
        Dim birthday As String = CType(sender, DataGridView).Rows(dgvcea.RowIndex).Cells(3).Value
        Dim mobile1 As String = CType(sender, DataGridView).Rows(dgvcea.RowIndex).Cells(4).Value
        Dim guomin As String = CType(sender, DataGridView).Rows(dgvcea.RowIndex).Cells(5).Value
        Dim jiwangbingshi As String = CType(sender, DataGridView).Rows(dgvcea.RowIndex).Cells(6).Value
        Dim doctor As String = CType(sender, DataGridView).Rows(dgvcea.RowIndex).Cells(7).Value
        Dim zhusu As String = CType(sender, DataGridView).Rows(dgvcea.RowIndex).Cells(8).Value
        Dim zhiliao As String = CType(sender, DataGridView).Rows(dgvcea.RowIndex).Cells(9).Value
        Dim beizhu As String = CType(sender, DataGridView).Rows(dgvcea.RowIndex).Cells(10).Value
        Me.updateRow(rowid, username, gender, birthday, mobile1, guomin, jiwangbingshi, doctor, zhusu, zhiliao, beizhu)
    End Sub

    Private Function selectAll() As System.Data.DataTable
        Using conn As MySqlConnection = New MySqlConnection("Server=127.0.0.1;Database=mydata;Uid=root;Pwd=;CharSet=gbk;")
            Using cmd As MySqlCommand = New MySqlCommand("select * from t_user order by rowid desc", conn)
                Using da As MySqlDataAdapter = New MySqlDataAdapter(cmd)
                    Using dt As DataTable = New DataTable()
                        da.Fill(dt)
                        Return dt
                    End Using
                End Using
            End Using
        End Using
    End Function
End Class

你可能感兴趣的:(android)