一个注册系统中总是给我插入一条空记录是怎么回事?
错误为:总是在数据库中有一条空记录!
第一次登陆,系统先查看有否用户名为空的记录(注册系统中的用户名起始位置是空),如果有,提示"用户已经存在",如果没有就把空记录插入到数据库中去,我现在把数据库中的username改为不允许为空了之后,运行给我提示错误信息"数据表中的username字段不允许为空",这是怎么搞的,应该怎么排除这个错误?
以下是代码:
' If (Page.IsValid) Then '如果各项值都通过验证
If Not Page.IsPostBack Then
'与数据库建立连接
Dim strconn As String = "provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("kygl.mdb")
Dim myconn As OleDb.OleDbConnection = New OleDb.OleDbConnection(strconn)
'打开链接
myconn.Open()
Dim strsql As String = "select * from zhuce where username='" + txtname.Text + "'"
Dim mycommand As OleDb.OleDbCommand = New OleDb.OleDbCommand(strsql, myconn)
'用reader对象来查询用户名是否已经存在
Dim reader As OleDb.OleDbDataReader
reader = mycommand.ExecuteReader()
If reader.Read() Then
If reader("username").ToString() = txtname.Text Then
'若存在
zhucelisterror.Text = "<p>用户已经存在"
'message.InnerHtml = "有该用户!"
reader.Close()
End If
Else
'不存在,则将该用户信息增加到数据库
reader.Close()
strsql = "insert into zhuce values ('" + txtname.Text + "','" + pasw.Text + "','" + txtemail.Text + "', false ,'" + Dropdownlist2.SelectedIndex.ToString() + "') "
mycommand = New OleDb.OleDbCommand(strsql, myconn)
'执行插入语句
mycommand.ExecuteNonQuery()
zhucelisterror.Text = "注册成功"
End If
'关闭链接
myconn.Close()
End If
问题点数:0、回复次数:1Top
1 楼blackcatiii(能教我做框架设计吗)回复于 2003-06-03 10:04:09 得分 0
你直接用Response.Write(strsql)输出sql语句检查一下是什么问题。Top




