Hey everyone. I received this sql server error and I can't figure out where the trouble is:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: 'Incorrect syntax near '​'.'

Source Error: Line: 46

Error Line: cmdsql.ExecuteNonQuery()

Dim connexcel As OleDbConnection
    Dim daexcel As OleDbDataAdapter
    Dim dsexcel As DataSet
    Dim cmdexcel As OleDbCommand
    Dim drexcel As OleDbDataReader

    Dim connsql As SqlConnection
    Dim dasql As SqlDataAdapter
    Dim dssql As DataSet
    Dim cmdsql As SqlCommand
    Dim drsql As SqlDataReader

    Private Sub import_excel_to_sql_server_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()
    End Sub

    Private Sub BtnImpExcelFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnImpExcelFile.Click
        On Error Resume Next
        OpenFileDialog1.Filter = "(* .xls) | * .xls | (*. Xlsx) | *. xlsx | All files (*. *) | *. * "
               OpenFileDialog1.ShowDialog()
        FileAdd.Text = OpenFileDialog1.FileName
        connexcel = New OleDbConnection("provider = Microsoft.ace.OLEDB.12.0; data source =" & FileAdd.Text & "; Extended Properties = Excel 8.0;")
        connexcel.Open()

        Dim dtSheets As DataTable = connexcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
        Dim listSheet As New List(Of String)
        Dim drSheet As DataRow

        For Each drSheet In dtSheets.Rows
            listSheet.Add(drSheet("TABLE_NAME").ToString())
        Next

        For Each sheet As String In listSheet
            ExcelSheetList.Items.Add(sheet)
        Next
    End Sub

    Private Sub ExcelSheetList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExcelSheetList.SelectedIndexChanged
        daexcel = New OleDbDataAdapter("select * from [" & ExcelSheetList.Text & "]", connexcel)
        dsexcel = New DataSet
        daexcel.Fill(dsexcel)
        DGVImpData.DataSource = dsexcel.Tables(0)
        DGVImpData.ReadOnly = True
    End Sub

    Sub connections()
        connsql = New SqlConnection("data source =. \ MSSMLBIZ; initial catalog = MyInvoice; integrated security = true")
        connsql.Open()
    End Sub

    Private Sub BtnSaveImpData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSaveImpData.Click
        For line As Integer = 0 To DGVImpData.RowCount - 2
            Call connections()
            Dim save As String = "insert into InvoiceData values ​​('" & DGVImpData.Rows(line).Cells(0).Value & "', '" & DGVImpData.Rows(line).Cells(1).Value & "')"
        cmdsql = New SqlCommand(save, connsql)
            cmdsql.ExecuteNonQuery()
        Next
        MsgBox("data saved successfully")
        DGVImpData.Columns.Clear()
    End Sub

Just a thought. Most filenames and paths do not have spaces after the dot or .

Also, if you are getting a syntax error in your query, it helps to print out the value of the query after you have concatenated in the variable text part.

commented: From memory we can add a debug.print to show it in Visual Studio. Also we can set a breakpoint on a line and mouse over the variable to peek at it. +0

I'm gonna guess Line 47 - the space between the period and the backslash. Syntax errors involving things like periods are tricky to run down at the best of times simply because the character itself is small and seems insignificant, so your brain tends to skip over it as unimportant. It takes awhile to train yourself out of that.