Imports System.Data.SqlClient
Imports System.IO
Public Class ClsAddUser
#Region "Fields and Properties"
Private _vc_UserId As String
Property vc_UserId
Get
Return _vc_UserId
End Get
Set(ByVal value)
_vc_UserId = value
End Set
End Property
Private _vc_Name As String
Property vc_Name
Get
Return _vc_Name
End Get
Set(ByVal value)
_vc_Name = value
End Set
End Property
Private _vc_Position As String
Property vc_Position
Get
Return _vc_Position
End Get
Set(ByVal value)
_vc_Position = value
End Set
End Property
Private _vc_Username As String
Property vc_Username
Get
Return _vc_Username
End Get
Set(ByVal value)
_vc_Username = value
End Set
End Property
Private _vc_Password As String
Property vc_Password
Get
Return _vc_Password
End Get
Set(ByVal value)
_vc_Password = value
End Set
End Property
Private _vc_Private As String
Property vc_Private
Get
Return _vc_Private
End Get
Set(ByVal value)
_vc_Private = value
End Set
End Property
#End Region
#Region "Constructors"
Private Sub PopulateDefault()
_vc_UserId = ""
_vc_Name = ""
_vc_Position = ""
_vc_Username = ""
_vc_Password = ""
_vc_Private = ""
End Sub
Sub New()
PopulateDefault()
End Sub
#End Region
Public sql As String
Dim ConstrEV As String
Public Function InsertUser_Admin() As Boolean
ConnS.Open()
'Dim intNumRows As Integer
'sql = " SELECT COUNT(*) FROM M_Users WHERE vc_UserId = '" & AddUserID & "' "
'cmd = New SqlCommand(sql, ConnS)
'MessageBox.Show(sql)
'intNumRows = cmd.ExecuteScalar()
'If intNumRows > 0 Then
' MessageBox.Show("Fail")
'Else
sql = " INSERT INTO M_Users("
sql += " vc_UserId, "
sql += " vc_Name, "
''sql += " vc_Position)"
'sql += " vc_Position, "
sql += " vc_Username, "
sql += " vc_Password, "
sql += " vc_Private)"
sql += " VALUES ("
sql += " @vc_UserId, "
sql += " @vc_Name, "
''sql += " @vc_Position)"
'sql += " @vc_Position, "
sql += " @vc_Username, "
sql += " @vc_Password, "
sql += " @vc_Private)"
Using cmd As New SqlCommand(sql)
cmd.Parameters.AddWithValue("@vc_UserId", AddUserID)
cmd.Parameters.AddWithValue("@vc_Name", InsertName)
'cmd.Parameters.AddWithValue("@vc_Position", StatusUser)
cmd.Parameters.AddWithValue("@vc_Username", InsertUserNm)
cmd.Parameters.AddWithValue("@vc_Password", InsertPass)
cmd.Parameters.AddWithValue("@vc_Private", StatusUser)
MessageBox.Show("บันทึกสำเร็จ")
InsertName = ""
StatusUser = ""
Return ExecuteNonQuery(cmd)
ConnS.Close()
End Using
'End if
End Function
End Class
เผื่อเป็นแนวได้นะครับ ของผมทำแบบนี้ครับ............. ASP.net (VB) ครับ
============================================================================================
Dim TB1 As String
TB1 = TextBox1.Text
Dim DataP As New TData
Dim DT As Data.DataTable = DataP.GetdataTable("select pro_id from product where pro_id = '" & TB1 & "' ")
If DT.Rows.Count > 0 Then
Label17.Text = "<span style='font-size:20px;color:red'>มีข้อมูลอยู่แล้ว</span>"
Else
Dim Data1 As New TData
Dim cmd As SqlCommand = Data1.CommandCreate("insert into product (pro_id,pro_name,pro_detail1pro_weight,pro_size,pro_color) values (@p1,@p2,@p3,@p4,@p5,@p6)", "TTTTTT")
cmd.Parameters(0).Value = TextBox1.Text
cmd.Parameters(1).Value = TextBox2.Text
cmd.Parameters(2).Value = TextBox3.Text
cmd.Parameters(3).Value = TextBox4.Text
cmd.Parameters(4).Value = TextBox5.Text
cmd.Parameters(5).Value = TextBox6.Text