Protected Sub btnsave_Click(sender As Object, e As EventArgs) Handles btnsave.Click
Dim year As Integer = Convert.ToInt32(DropDownList4.SelectedValue)
Dim day As String = Convert.ToString(year) + "-" + DropDownList3.SelectedValue + "-" + DropDownList2.SelectedValue
If IsDate(day) = False Then
Dim script3 As String = "alert('กรุณาระบุวันเกิดอีกครั้ง!');"
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "jsCall", script3, True)
Exit Sub
End If
Dim intCount As Integer
Dim Conn As New SqlConnection(strCon)
Conn.Open()
Dim sql As String = "SELECT COUNT(*) FROM REGISTER WHERE USERNAME = '%" & txtusername.Text & "%'"
Dim com As New SqlCommand
With com
.Connection = Conn
.CommandText = sql
.CommandType = CommandType.Text
End With
intCount = com.ExecuteScalar()
If intCount > 0 Then
Dim script3 As String = "alert('ชื่อผู้ใช้มีอยู่แล้ว!');"
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "jsCall", script3, True)
Exit Sub
Else
Dim sqlb As String = "INSERT INTO [REGISTER]([USERNAME],[PASS],[NAME],[SURNAME],[DATE_OF_BIRTH],[GENDER],[STATUS_ID]) VALUES ( '" + txtusername.Text + "', '" + txtpass.Text + "','" + txtname.Text + "','" + txtsurname.Text + "','" & day & "','" + DropDownList1.SelectedValue + "','2')"
'--------------------------------------------------------------
Dim cmd1 = New SqlCommand
With cmd1
.Connection = Conn
.CommandType = CommandType.Text
.CommandText = sqlb
End With
cmd1.ExecuteNonQuery()
Conn.Close()
Response.Redirect("index.aspx")
End If
End Sub
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VB.NET, VS 2012 (.NET 4.x)