Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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()
Posted

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.
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900