Results 1 to 2 of 2

Thread: I have connection error Declaration Expected

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001

    Question I have connection error Declaration Expected

    I am learning database with visual basic 2012, I would like to build my very first own application I am using only one table because is a small program.

    I got an error "Declaration Expected" on my connection string. This string I had copied when I create the database, MyCn is not reconnoitered by the compiler. I suppose to use my connection with ADO.NET - OLEDB in Visual Basic 2012.

    Imports System.IO
    Imports System.Data.SqlClient

    Public Class Form1
    Dim ShowRecords()

    Private MyCn As New SqlClient.SqlConnection

    MyCn = Data Source=DESKTOP-I0FPTF2\SQLEXPRESS;Initial Catalog=Estimates;Integrated Security=True;Pooling=False


    Private MyDatAdp As New SqlClient.SqlDataAdapter
    Private MyCmdBld As New SqlClient.SqlCommandBuilder
    Private MyDataTbl As New DataTable

    Private MyRowPosition As Integer = 0

  2. #2
    Fanatic Member
    Join Date
    Nov 2017

    Re: I have connection error Declaration Expected

    There may be more than 1 problem with the code snippet you posted, but the first thing that needs to get fixed is that you need quotation marks around your connection string:

    "Data Source=DESKTOP-I0FPTF2\SQLEXPRESS;Initial Catalog=Estimates;Integrated Security=True;Pooling=False"
    That is as much as I can help with, good luck.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width