Imports System.Data
Imports System.Data.SqlClient
Partial Public Class adduser
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.pnlFinish.Visible = False
End Sub
Protected Sub btnRegister_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRegister.Click
Dim objConn As SqlConnection
Dim strConnString As String
Dim strSQL As StringBuilder
Dim objCmd As SqlCommand
Dim intCount As Integer = 0
'*** Open Connection ***'
strConnString = "Server=ULTRAMOSHI-PC;UID=sa;PASSWORD=;Database=RM2013;Max Pool Size=400;Connect Timeout=600;"
objConn.ConnectionString = strConnString
objConn.Open()
'*** Check Username exists ***'
strSQL = New StringBuilder
strSQL.Append(" SELECT COUNT(*) FROM personnel ")
strSQL.Append(" WHERE Username = @sUsername ")
objCmd = New SqlCommand(strSQL.ToString(), objConn)
objCmd.Parameters.Add("@sUsername", SqlDbType.VarChar).Value = Me.txb_nameper.Text
intCount = objCmd.ExecuteScalar()
If intCount >= 1 Then
Me.lblStatus.ForeColor = Drawing.Color.Red
Me.lblStatus.Text = "Username already exists!!"
Exit Sub
End If
'*** Insert New Member ***'
strSQL = New StringBuilder
strSQL.Append(" INSERT INTO personnel ")
strSQL.Append(" (title,name_per,lastname_per,tell,sex,birthday,position,start_time,name_workgroup,Password) ")
strSQL.Append(" VALUE ")
strSQL.Append(" (@stitle,@sname_per,@slastname_per,@stell,@ssex,@sbirthday,@sposition,@sstart_time,@sname_workgroup,@sPassword) ")
objCmd = New SqlCommand(strSQL.ToString(), objConn)
objCmd.Parameters.Add("@stitle", SqlDbType.VarChar).Value = Me.title_name.Text
objCmd.Parameters.Add("@sname_per", SqlDbType.VarChar).Value = Me.txb_nameper.Text
objCmd.Parameters.Add("@slastname_per", SqlDbType.VarChar).Value = Me.txb_lastnameper.Text
objCmd.Parameters.Add("@stell", SqlDbType.VarChar).Value = Me.txb_tell.Text
objCmd.Parameters.Add("@ssex", SqlDbType.VarChar).Value = Me.sex.Text
objCmd.Parameters.Add("@sbirthday", SqlDbType.VarChar).Value = Me.birthday.Text
objCmd.Parameters.Add("@sposition", SqlDbType.VarChar).Value = Me.ddb_position.Text
objCmd.Parameters.Add("@sstart_time", SqlDbType.VarChar).Value = Me.start_time.Text
objCmd.Parameters.Add("@sname_workgroup", SqlDbType.VarChar).Value = Me.ddb_workgroup.Text
objCmd.Parameters.Add("@sPassword", SqlDbType.VarChar).Value = Me.txb_Password.Text
objCmd.ExecuteNonQuery()
objConn.Close()
objConn = Nothing
Me.pnlFinish.Visible = True
End Sub
End Class