Sub enter_click(ByVal sender As Object, ByVal e As EventArgs)
Dim conn As New SqlConnection("server=localhost;database=education;uid=sa;pwd=")
Dim strsql1 As String
strsql1 = "select * from login where userid='" & userid.text & "'"
Dim cmd As New SqlCommand(strsql1, conn)
conn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.Read() Then
message.Text = "帐号已经注册过"
conn.Close()
Else
Dim strsql2 As String
strsql2 = "insert into login(userid,password,sex,birthday,email,telephone,name) values ('" & userid.Text & "','" & password.Text & "','" & sex.SelectedItem.Text & "','" & birthday.Text & "','" & email.Text & "','" & telephone.Text & "','" & name.Text & "')"
Dim cmdr As New SqlCommand(strsql2, conn)
'Try
cmdr.ExecuteNonQuery()
conn.Close()
Response.Redirect("index.aspx")
' Catch ex As Exception
' message.Text = "没有注册成功"
' End Try
End If
End Sub
Dim conn As New SqlConnection("server=localhost;database=education;uid=sa;pwd=")
Dim strsql1 As String
strsql1 = "select * from login where userid='" & userid.text & "'"
Dim cmd As New SqlCommand(strsql1, conn)
conn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.Read() Then
message.Text = "帐号已经注册过"
conn.Close()
Else
Dim strsql2 As String
strsql2 = "insert into login(userid,password,sex,birthday,email,telephone,name) values ('" & userid.Text & "','" & password.Text & "','" & sex.SelectedItem.Text & "','" & birthday.Text & "','" & email.Text & "','" & telephone.Text & "','" & name.Text & "')"
Dim cmdr As New SqlCommand(strsql2, conn)
'Try
cmdr.ExecuteNonQuery()
conn.Close()
Response.Redirect("index.aspx")
' Catch ex As Exception
' message.Text = "没有注册成功"
' End Try
End If
End Sub
解决方案 »
- C#中SQL语句预编译的问题、prepareStatement
- C#创建XML文件问题,在线等
- 系统做如何本地存储
- C#中C/S开发如何做到瘦客户端
- .net2005 下建了两个工程:一个是C#的另一个是C++的,遇到一些问题,请大家帮忙看看
- C#中要显示一些柱图啊,饼图啊.有这样的控件吗?
- 我得到了一个 string ,怎样才能转换成 StreamReader,然后作为参数传给另外一个函数呢?
- 我写了一个BS的应用程序,使用者很多,如何有效的计算机正在使用的人数呢?
- 怎么读取文件 然后修改其中的内容
- (WinForms 问题)怪了,NumericUpDown 的 OnPaint 竟然无法 Override。
- 如何在datagridview中的cell中自动填入数据(winform)!
- 在C#中如何定义一个公用的结构体?
message.Text = "帐号已经注册过"
dr.Close()
conn.Close()
Else
dr.Close()
Dim strsql2 As String
strsql2 = "insert into login(userid,password,sex,birthday,email,telephone,name) values ('" & userid.Text & "','" & password.Text & "','" & sex.SelectedItem.Text & "','" & birthday.Text & "','" & email.Text & "','" & telephone.Text & "','" & name.Text & "')"
Dim cmdr As New SqlCommand(strsql2, conn)
'Try
cmdr.ExecuteNonQuery()
conn.Close()
Response.Redirect("index.aspx")
' Catch ex As Exception
' message.Text = "没有注册成功"
' End Try
End If
conn.Close()
ps:你的代码设计有问题...书写格式也不正规。
建议
try
{
}catch(Execption e)
{
}
finally
{
if(dr!=null)
dr.Close();
if(con.State==ConnectionState.Open)
conn.Close();
}
If dr.Read() Then
message.Text = "帐号已经注册过"
Else
Dim strsql2 As String
strsql2 = "insert into login(userid,password,sex,birthday,email,telephone,name) values ('" & userid.Text & "','" & password.Text & "','" & sex.SelectedItem.Text & "','" & birthday.Text & "','" & email.Text & "','" & telephone.Text & "','" & name.Text & "')"
Dim cmdr As New SqlCommand(strsql2, conn)
'Try
cmdr.ExecuteNonQuery()
Response.Redirect("index.aspx")
' Catch ex As Exception
' message.Text = "没有注册成功"
' End Try
End If
dr.close()
conn.Close()