Imports MySql.Data.MySqlClient
Public Class Form_coun
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=112.121.151.206;User Id=xxxxxxx; Password=xxxxxx; Database=ycklninh_counselor;"
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 (nickname, email, subj_head, sub_subj,code,type) VALUES ('" + txtnickname.Text + "','" + txtemail.Text + "','" + txtsubj_head.Text + "','" + txtsub_subj.Text + "','" + txtcode.Text + "','ยังไม่ได้แก้ไข')"
Mycommand.Connection = Conn
Mycommand.CommandText = sqlquery
mydata = Mycommand.ExecuteReader()
MsgBox("ส่งข้อมูลเก็บสู่ระบบเรียบร้อยแล้ว")
Me.Hide()
Else
index.Show()
End If
End Sub
End Class