Radio Button
I have radio button for user to select Is Administrator(Yes/No), i group them, but can't assign the same name for that 2 button. That's why I can't retrieve the value of user's selection. What should I do?
[code]
Dim FirstTime, Admin As Char
Private Sub rbtnAdmin_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnAdmin.CheckedChanged
Admin = "Y"
End Sub
Private Sub rbtnNotAdmin_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnNotAdmin.CheckedChanged
Admin = "N"
End Sub
Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
Dim con As New SqlConnection("data source=localhost; initial catalog=""E-Library Records""; user id=sa")
Dim str = "SELECT * FROM [UserAccount] WHERE User_id = '" & txtUserID.Text & "'"
Dim dr As SqlDataReader
Dim da As SqlDataAdapter
Dim sSQL As New SqlCommand
With sSQL
sSQL.Connection = con
sSQL.Connection.Open()
sSQL.CommandText = str
sSQL.CommandType = CommandType.Text
dr = sSQL.ExecuteReader()
End With
Dim User_id, UserID, User_Password, Pwd, str1 As String
Dim FirstTime, Admin As RadioButton
If dr.HasRows Then
Response.Write("Sorry, the User ID already exists. Please try again.")
Else
User_id = txtUserID.Text
User_Password = txtPwd.Text
User_id = User_id.Trim
User_Password = User_Password.Trim
If User_Password.Length < 4 Or User_Password.Length > 10 Then
Response.Write("Password must be 4-10 characters!")
End If
Try
str1 = "INSERT INTO UserAccount Values (@User_id," _
& "@User_Password, @IsFirstTime, @IsAdministrator)"
Dim InsCom As New SqlCommand(str1, con)
da.InsertCommand = InsCom
con.Open()
da.InsertCommand.Parameters.Add(New _
SqlParameter("@User_id", SqlDbType.Char, 10))
da.InsertCommand.Parameters.Add(New _
SqlParameter("@User_Password", SqlDbType.Char, 10))
da.InsertCommand.Parameters.Add(New _
SqlParameter("@IsFirstTime", SqlDbType.Char, 1))
da.InsertCommand.Parameters.Add(New _
SqlParameter("@IsAdministrator", SqlDbType.Char, 1))
da.InsertCommand.Parameters("@User_id").Value = txtUserID.Text
da.InsertCommand.Parameters("@User_Password").Valu e = txtPwd.Text
da.InsertCommand.Parameters("@IsFirstTime").Value = Request.Form("FirstTime")
da.InsertCommand.Parameters("@IsAdministrator").Va lue = Request.Form("Admin")
da.InsertCommand.ExecuteNonQuery()
con.Close()
Response.Redirect("Admin1.aspx")
Catch err As SystemException
Finally
End Try
End If
con.Close()
dr.Close()
End Sub
When I debug, I found out that when the execution reach con.Open(), it will go to Catch err As SystemException directly, Is it mean the InsertCommand is not executed?
Can somebody help me? Thank you.
Irene
|