我创建了一个使用SQL Server数据库作为后端的ASP.Net项目。我显示以下错误。如何解决这个问题?SQL Server 2005中使用ASP.Net的问题
===============编码
Imports System.Data.SqlClient
Partial Class Default2
Inherits System.Web.UI.Page
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim ra As Integer
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
myConnection = New SqlConnection("Data Source=JANANI-FF079747\SQLEXPRESS;Initial Catalog=new;Persist Security Info=True;User ID=sa;Password=janani") 'server=localhost;uid=sa;pwd=;database=pubs")
myConnection.Open()
myCommand = New SqlCommand("Insert into table3 values 'janani','jan'")
ra = myCommand.ExecuteNonQuery() ========---> error is showing here
MsgBox("New Row Inserted" & ra)
myConnection.Close()
End Sub
End Class
=========错误消息============
ExecuteNonQuery: Connection property has not been initialized.
+1。这是我做这件事的方式。我在上面回答时很懒惰。希望你会得到接受的答案。 – 2010-03-09 07:11:30
不,再次出现同样的错误,如何解决这个问题 – user246160 2010-03-09 10:19:54
@megala你用上面提供的代码替换了上面的代码吗?如果没有,请做到这一点,然后再试一次。另外,如果再次失败,请发布完整的代码和错误消息。 – 2010-03-09 15:22:19