If Page.IsValid Then
'从文件Web.config中读取连接字符串
Dim strconn As String = ConfigurationSettings.AppSettings("dsn")
'连接本地计算机的bookonline数据库
Dim cn As New SqlConnection(strconn)
cn.Open()
Dim sqlstr As String = "insert into user(userid) values('" & Trim(TextBox1.Text) & "') "
Dim myCommand As New SqlCommand(sqlstr, cn)
myCommand.Connection = cn
myCommand.Connection.Open()
myCommand.CommandText = sqlstr
myCommand.ExecuteNonQuery()
'关闭连接
cn.Close()
cn = Nothing
Response.Write("<script>alert('注册已经成功!')</script>") 以上是我想用textbox 写东西到数据库里 可是却报错 错误如下:
“/bookonline”应用程序中的服务器错误。
-------------------------------------------------------------------------------- 连接已经打开(state=Open)。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 连接已经打开(state=Open)。 源错误:
行 49: Dim myCommand As New SqlCommand(sqlstr, cn)
行 50: myCommand.Connection = cn
行 51: myCommand.Connection.Open()
行 52: myCommand.CommandText = sqlstr
行 53: myCommand.ExecuteNonQuery()
源文件: D:\winter\bookonline\WebForm3.aspx.vb 行: 51 堆栈跟踪:
[InvalidOperationException: 连接已经打开(state=Open)。]
System.Data.SqlClient.SqlConnection.Open() +420
bookonline.WebForm3.Button1_Click(Object sender, EventArgs e) in D:\winter\bookonline\WebForm3.aspx.vb:51
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
谁能帮我看看啊 我的代码有问题吗?
'从文件Web.config中读取连接字符串
Dim strconn As String = ConfigurationSettings.AppSettings("dsn")
'连接本地计算机的bookonline数据库
Dim cn As New SqlConnection(strconn)
cn.Open()
Dim sqlstr As String = "insert into user(userid) values('" & Trim(TextBox1.Text) & "') "
Dim myCommand As New SqlCommand(sqlstr, cn)
myCommand.Connection = cn
myCommand.Connection.Open()
myCommand.CommandText = sqlstr
myCommand.ExecuteNonQuery()
'关闭连接
cn.Close()
cn = Nothing
Response.Write("<script>alert('注册已经成功!')</script>") 以上是我想用textbox 写东西到数据库里 可是却报错 错误如下:
“/bookonline”应用程序中的服务器错误。
-------------------------------------------------------------------------------- 连接已经打开(state=Open)。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 连接已经打开(state=Open)。 源错误:
行 49: Dim myCommand As New SqlCommand(sqlstr, cn)
行 50: myCommand.Connection = cn
行 51: myCommand.Connection.Open()
行 52: myCommand.CommandText = sqlstr
行 53: myCommand.ExecuteNonQuery()
源文件: D:\winter\bookonline\WebForm3.aspx.vb 行: 51 堆栈跟踪:
[InvalidOperationException: 连接已经打开(state=Open)。]
System.Data.SqlClient.SqlConnection.Open() +420
bookonline.WebForm3.Button1_Click(Object sender, EventArgs e) in D:\winter\bookonline\WebForm3.aspx.vb:51
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
谁能帮我看看啊 我的代码有问题吗?
解决方案 »
- 如何给域用户分配权限
- AutoCompleteExtender控件的OnClientItemSelected方法
- 同一个groupname的许多(比如100个)radiobutton如何取到所选择的radiobutton
- 如何添加iis6.0管理员
- 求教ASP.NET
- 请教:DataGrid中显示小图片的问题
- 怎么总是说我没有默认打印机呀?在.aspx上的打印问题!
- 刷新页面后,窗口老是自己弹出来,怎样才可以搞好
- 在线等。。。。能不能把DataGrid绑定列的值 用数组元素付。
- DataGrid中怎么样实现手动调整列的宽度??
- 急,100分求救,解答完马上结帖~~~~
- asp,asp.net,c# 之间有什么联系吗
注释这句 cn.Open() 因为你已经打开连接 所以在51行试图再打开连接时报错
’myCommand.Connection.Open()
‘ myCommand.CommandText = sqlstr