How to solve ERROR The ConnectionString property has not been initialized.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bellr120
    New Member
    • May 2014
    • 1

    How to solve ERROR The ConnectionString property has not been initialized.

    I am getting an error in the following code.
    The error message is "The ConnectionStrin g property has not been initialized."

    How can I resolve this?

    Code:
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    
            Dim strsql7 As String
            Dim cm7 As New SqlCommand
            Dim dt7 As New DataTable
            Dim da7 As New SqlDataAdapter
            conn.openDatabase()
    
            strsql7 = "SELECT username, password, name , money  FROM member  where  username='" & TextBox7.Text & "' "
    
            strsql7 = strsql7 & " union "
    
            strsql7 = strsql7 & "SELECT username, password, name_admin , money  FROM admin  where  username='" & TextBox7.Text & "' "
    
    
            cm7.Connection = conn.sqlConnDB
            cm7.CommandText = strsql7
            da7.SelectCommand = cm7
            da7.Fill(dt7)
    Last edited by Frinavale; May 7 '14, 01:15 PM. Reason: Added the question stated in the title of the thread to the body of the thread so that it makes more sense than just a block of code.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    In order to connect to a database you have to specify how to do so. This is done with a connection string.

    I do not see you using a connection string in your code.

    Check out the documentation for Connection String Syntax to learn how to use one.

    -Frinny

    Comment

    Working...