用于连接到Visual Studio 2010中的数据库的Web应用程序查询 [英] web application query for connection to database in Visual studio 2010
问题描述
此代码将连接错误视为
[ ]
Dim strConnString As [String] = System.Configuration。 _ $ / $
ConfigurationManager.ConnectionStrings(conString)_。ConnectionString()
Dim con As New SqlConnection(strConnString)
Dim strQuery As String =select * from tb order by id
Dim cmd As New SqlCommand(strQuery)
Dim sda As New SqlDataAdapter()
cmd.CommandType = CommandType.Text
cmd.Connection = con
试试
con.Open()
sda.SelectCommand = cmd
sda.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
Catch ex As Exception
Response.Write(ex 。消息)
最后
con.Close()
sda.Dispose()
con.Dispose()
this code gives the errors in connection as
[]
Dim strConnString As [String] = System.Configuration. _
ConfigurationManager.ConnectionStrings("conString")_.ConnectionString()
Dim con As New SqlConnection(strConnString)
Dim strQuery As String = "select * from tb order by id"
Dim cmd As New SqlCommand(strQuery)
Dim sda As New SqlDataAdapter()
cmd.CommandType = CommandType.Text
cmd.Connection = con
Try
con.Open()
sda.SelectCommand = cmd
sda.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
Finally
con.Close()
sda.Dispose()
con.Dispose()
推荐答案
好吧,你的帖子难以辨认,但是,虽然你的代码非常糟糕(你不应该把你的数据库代码放在你的表示层中,一开始),但我觉得它应该有用。你需要告诉我们错误是什么,或者只是阅读它(我们会告诉你它意味着它的含义)。很可能你的连接字符串坏了或你根本无法连接到你的数据库。
Well, your post is illegible, but, while your code is pretty awful ( you should never put your DB code in your presentation layer, for a start ), it looks to me like it should work. You need to tell us what the error is, or perhaps just read it ( we will tell you it means what it says ). Odds are good your connection string is broken or you can''t connect to your DB at all.
对不起这一切它在编译时没有错误但是当我执行它时给了我用户代码未处理NULLReferenceException错误
此行
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings(conString)。ConnectionString
sorry for all this it has no error at compile time but when I execute it gives me the error of NULLReferenceException was unhandled by the user code
at this line
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings("conString").ConnectionString
这篇关于用于连接到Visual Studio 2010中的数据库的Web应用程序查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!