sqlcom1.commandtext="insert into users(usr,pwd,name,address,email,description)values('"& txtuser.text &"','"& txtpwd.text &"','"& txtname.text &"','"& txtaddress.text &"','"& txtemail.text &"','"& txtcontent.text &"')"
sqlcom.executenonquery;//这儿为什么是sqlcom而不是sqlcom1
sqlcom.executenonquery;//这儿为什么是sqlcom而不是sqlcom1
dim sqlcom1 as new sqlcommand
sqlcom1.connection=sqlcon
sqlcom1.commandtext="insert into users(usr,pwd,name,address,email,description)values('"& txtuser.text &"','"& txtpwd.text &"','"& txtname.text &"','"& txtaddress.text &"','"& txtemail.text &"','"& txtcontent.text &"')"
sqlcom.executenonquery //应该是这里的问题?sqlcom1
sqlcom1.commandtext=@"insert into users(usr,pwd,name,address,email,description) values('"& txtuser.text &"','"& txtpwd.text &"','"& txtname.text &"','"& txtaddress.text &"','"& txtemail.text &"','"& txtcontent.text &"')"
这里要重新建立一个连接。 dim sqlcon1 as new sqlconnection("server=YYH;database=register;uid=sa;pwd=123456")
sqlcon1.open
dim sqlcom1 as new sqlcommand sqlcom1.connection=sqlcon1(改为sqlcon1) sqlcom1.commandtext="insert into users(usr,pwd,name,address,email,description)values('"& txtuser.text &"','"& txtpwd.text &"','"& txtname.text &"','"& txtaddress.text &"','"& txtemail.text &"','"& txtcontent.text &"')"
sqlcom1.executenonquery
sqlcon1.close
//这里改了
sqlcom1=nothing
sqlcon1=nothing dg.edititemindex=-1
bindgrid '调用函数以重新显示
else
lblcontent.text="该用户名在数据库中已经存在,添加失败!"
end ifsqlcon.close ///这里改了
sqlcom=nothing
sqlcon=nothing
救命啊
提示:ExecuteNonQuery 需要打开的并且可用的连接。该连接的当前状态是 Closed
dim sqlcon as new sqlconnection("server=YYH;database=register;uid=sa;pwd=123456")
sqlcon.open
dim sqlcom as new sqlcommand
sqlcom.connection=sqlcon
sqlcom.commandtext="select * from users where usr='"& txtuser.text &"'"
dim myreader as sqldatareader
myreader=sqlcom.executereader if not myreader.read then
myreader.close() //*****关闭myreader******
dim sqlcom1 as new sqlcommand
sqlcom1.connection=sqlcon
sqlcom1.commandtext="insert into users(usr,pwd,name,address,email,description) values('"& txtuser.text &"','"& txtpwd.text &"','"& txtname.text &"','"& txtaddress.text &"','"& txtemail.text &"','"& txtcontent.text &"')" //***** description) values( ****** 加了一个空格
sqlcom1.executenonquery
sqlcon.close
sqlcom=nothing
sqlcom1=nothing
sqlcon=nothing dg.edititemindex=-1
bindgrid '调用函数以重新显示
else
lblcontent.text="该用户名在数据库中已经存在,添加失败!"
sqlcon.close
sqlcon=nothing
sqlcom=nothing
end if
end sub