Imports MySql.Data.MySqlClient
Imports System.Data
Public Class txtage
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
Dim Conn As MySqlConnection
Conn = New MySqlConnection()
Conn.ConnectionString = "Server=203.101.30.57; Database=xxxxx; Uid=xxxx; Pwd=xxxx; Character Set=utf8;"
Try
Conn.Open()
Catch myerror As MySqlException
MsgBox("ติดต่อฐานข้อมูลไม่ได้")
End Try
Dim myAdapter As New MySqlDataAdapter
Dim sqlquery = "SELECT * FROM data WHERE code = '" + txtcode.Text + "' "
Dim Mycommand As New MySqlCommand()
Mycommand.Connection = Conn
Mycommand.CommandText = sqlquery
myAdapter.SelectCommand = Mycommand
Dim mydata As MySqlDataReader
mydata = Mycommand.ExecuteReader()
If mydata.HasRows = 0 Then
Conn.Close()
Conn.Open()
sqlquery = " INSERT INTO data (day, month, year,nickname,age,sex,class,subj_head,subj_punha,subj_pon,type,code) VALUES ('" + txtdate.Text + "','" + txtmonth.Text + "','" + txtyear.Text + "','" + txtnickname.Text + "','" + txtage2.Text + "','" + txtsex.Text + "','" + txtclass.Text + "','" + txtsubj_head.Text + "','" + txtpunha.Text + "','" + txtpon.Text + "','ยังไม่ได้แก้ไข','" + txtcode.Text + "')"
Mycommand.Connection = Conn
Mycommand.CommandText = sqlquery
mydata = Mycommand.ExecuteReader()
MsgBox("บันทึกข้อมูลสู่ระบบแล้ว")
Conn.Close()
Me.Hide()
Else
index.Show()
End If
End Sub
Private Sub txtclass_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtclass.SelectedIndexChanged
End Sub
End Class