Imports MySql.Data.MySqlClient
Imports System.Data
Public Class Member
Dim strUser As String
Dim MySqlConnection As MySqlConnection
Dim objConn As New MySqlConnection
Dim objCmd As New MySqlCommand
Dim strConnString, strSQL As String
Sub Page_Load(sender As Object, e As EventArgs)
strConnString = "server=****** ; user id=******; password=******; database=******; Pooling=false"
objConn.ConnectionString = strConnString
objConn.Open()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim intNumRows As Integer
strSQL = "SELECT * FROM smsfree WHERE id = '" & Me.TextID.Text & "' "
objCmd = New MySqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
If intNumRows > 0 Then
Else
strSQL = "INSERT INTO smsfree (id,user,pass,email,phone,point) " & _
" VALUES " & _
" ('" & Me.TextID.Text & "','" & Me.TextBox1.Text & "','" & Me.TextBox2.Text & "', " & _
" '" & Me.TextBox3.Text & "','" & Me.TextBox4.Text & "','" & Me.TextBox5.Text & "')"
objCmd = New MySqlCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Try
objCmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox("Erorr")
End Try
End If
End Sub
End Class
Dim obj As Object = objCmd.ExecuteScalar()
'intNumRows = objCmd.ExecuteScalar() 'ในบางกรณีมันแปลงเป็น Integer ดื้อฯไม่ได้ครับ
If ([Object].Equals(obj, Nothing)) OrElse ([Object].Equals(obj, System.DBNull.Value)) Then
intNumRows = -12345
Else
intNumRows = Convert.ToInt32(obj)
End If