i have this insert code and its giving errors because there is something wrong with the connection string.

Dim MyConnection As SqlConnection
        Dim SqlString As String = "INSERT INTO items_table (item)  VALUES ('" & Me.txtItem.Text & "')"
        'Dim data_base As String = " Data Source=.\SQLEXPRESS;AttachDbFilename="C:\vb2008\Visual Studio 2008\Projects\morevariables\morevariables\App_Data\test_db.mdf";Integrated Security=True;User Instance=True"
        Dim data_base As String = " C:\vb2008\Visual Studio 2008\Projects\morevariables\morevariables\App_Data\test_db.mdf";Integrated Security=True;User Instance=True"
        MyConnection = New SqlConnection("Data Source=" & data_base)
        Dim concom As SqlCommand = MyConnection.CreateCommand()
        MyConnection.Open()
        Dim cmnd As SqlCommand = New SqlCommand(SqlString, MyConnection)
        cmnd.ExecuteNonQuery()        ' Execute the command here
        MyConnection.Close()

Remove double quote " chars from the connection string database path.

Dim MyConnection As SqlConnection

Dim SqlString As String = "INSERT INTO items_table (item)  VALUES (@item)"

Dim data_base As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\vb2008\Visual Studio 2008\Projects\morevariables\morevariables\App_Data\test_db.mdf;Integrated Security=True;User Instance=True"

MyConnection = New SqlConnection(data_base)

MyConnection.Open()

Dim cmnd As SqlCommand = New SqlCommand(SqlString, MyConnection)

cmnd.Parameters.AddWithValue("@item",Me.txtItem.Text)

cmnd.ExecuteNonQuery()        ' Execute the command here

MyConnection.Close()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.