Imports System.Data.SqlClient
Imports System.Data
Public Class frm_popup2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Try
If TextBox1.Text = "" And TextBox2.Text = "" And TextBox3.Text = "" Then
Label1.Text = "กรุณากรอบข้อมูลก่อนนะ"
End If
Dim objConn As SqlConnection
Dim strConnString As String
Dim strSQL As StringBuilder
Dim objCmd As SqlCommand
Dim intCount As Integer = 0
Dim _date As String = DateAndTime.Now
'*** Open Connection ***'
strConnString = "Data Source=ComD01-PC\E_001_SERVER;Initial Catalog=E_001;Persist Security Info=True;User ID=sa;Password=1234567890"
objConn = New SqlConnection
objConn.ConnectionString = strConnString
objConn.Open()
'*** Check Username exists ***'
strSQL = New StringBuilder
strSQL.Append(" SELECT COUNT(*) FROM popup ")
strSQL.Append(" WHERE num1 = @ID ")
objCmd = New SqlCommand(strSQL.ToString(), objConn)
objCmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = Me.TextBox1.Text
intCount = objCmd.ExecuteScalar()
If intCount >= 1 Then
Me.Label1.ForeColor = Drawing.Color.Red
Me.Label1.Text = "มีข้อมูลนี้ในระบบแล้ว"
Return
End If
'*** Insert New Member ***'
strSQL = New StringBuilder
strSQL.Append(" INSERT INTO popup ")
strSQL.Append(" (num1,num2,num3)")
strSQL.Append(" VALUES ")
strSQL.Append(" (@ID,@Name,@Area) ")
objCmd = New SqlCommand(strSQL.ToString(), objConn)
objCmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = TextBox1.Text
objCmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = TextBox2.Text
objCmd.Parameters.Add("@Area", SqlDbType.VarChar).Value = TextBox3.Text
objCmd.ExecuteNonQuery()
objConn.Close()
objConn = Nothing
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
Catch ex As Exception
End Try
End Sub
End Class