附加信息:关键字“FROM”附近的语法不正确

时间:2016-05-02 22:20:55

标签: sql vb.net

我一直在研究这个问题感觉,是否有人知道dang语法错误在哪里?这是代码:

Imports System.Data.SqlClient
Public Class Form1

    Dim newData As Boolean


    Private Sub TableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TableBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.TableBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.CustInfo)

    End Sub


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'CustInfo.Table' table. You can move, or remove it, as needed.
        showData()

        newData = True


    End Sub


    Sub showData()
        connDB()
        Dim dA As SqlDataAdapter = New SqlDataAdapter("SELECT Cust_ID, Cust_Name, Spouse Name, Phone Number, Address, Application Status, Broker Assigned, Broker Contact, FROM table", conn)
        Dim dS As DataSet = New DataSet
        dS.Clear()
        dA.Fill(dS, "table")
        TableDataGridView.DataSource = dS
        TableDataGridView.DataMember = "table"
        TableDataGridView.Enabled = True
        dA.Dispose()
        conn.Close()


    End Sub

    Private Sub fillTextbox(ByVal x As Integer)
        Try
            Cust_IDTextBox = TableDataGridView.Rows(x).Cells(0).Value
            Customer_NameTextBox = TableDataGridView.Rows(x).Cells(1).Value
            Spouse_NameTextBox = TableDataGridView.Rows(x).Cells(2).Value
            Phone_NumberTextBox = TableDataGridView.Rows(x).Cells(3).Value
            AddressTextBox = TableDataGridView.Rows(x).Cells(4).Value
            Application_StatusTextBox = TableDataGridView.Rows(x).Cells(5).Value
            Broker_AssignedLabel2 = TableDataGridView.Rows(x).Cells(6).Value
            Broker_ContactLabel2 = TableDataGridView.Rows(x).Cells(7).Value

        Catch ex As Exception

        End Try
    End Sub


    Private Sub TableDataGridView_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles TableDataGridView.CellContentClick
        fillTextbox(e.RowIndex)
        newData = False

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Cust_IDTextBox.Text = ""
        Customer_NameTextBox.Text = ""
        Spouse_NameTextBox.Text = ""
        Phone_NumberTextBox.Text = ""
        AddressTextBox.Text = ""
        Phone_NumberTextBox.Text = ""
        Application_StatusTextBox.Text = ""
        Broker_AssignedLabel2.Text = ""
        Broker_ContactLabel2.Text = ""

    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim save As String
        Dim message As String
        If Cust_IDTextBox.Text = "" Then Exit Sub
        If newData Then
            message = MsgBox("save", vbYesNo, vbInformation)
            If message = vbYesNo Then
                Exit Sub
            End If


            save = "INSERT INTO TABLE(Cust_ID, Cust_Name, Spouse Name, Phone Number, Address, Application Status, Broker Assigned, Broker Contact) VALUES('" & Cust_IDTextBox.Text & "', '" & Customer_NameTextBox.Text & "', '" & Spouse_NameTextBox.Text & "','" & Phone_NumberTextBox.Text & "', '" & AddressTextBox.Text & "', '" & Application_StatusTextBox.Text & "', '" & Broker_AssignedLabel2.Text & "', '" & Broker_ContactLabel2.Text & "')"

        Else
            message = MsgBox("update?", vbYesNo, vbInformation)
            If message = vbYesNo Then Exit Sub

            save = "UPDATE table SET Cust_Name='" & Customer_NameTextBox.Text & "', Spouse Name='" & Spouse_NameTextBox.Text & "', Address='" & AddressTextBox.Text & "', Application Status='" & Application_StatusTextBox.Text & "', Broker Assgined='" & Broker_AssignedLabel2.Text & "', Broker Contact='" & Broker_ContactLabel2.Text & "' WHERE Cust_ID='" & Cust_IDTextBox.Text & "'"

        End If

        runSql(save)
        showData()


    End Sub

    Private Sub runSql(ByVal SQL As String)
        Dim cmd As New SqlCommand
        connDB()
        Try
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = SQL
            cmd.ExecuteNonQuery()
            cmd.Dispose()
            conn.Close()
            MsgBox("done")

        Catch ex As Exception

        End Try

    End Sub
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim deleteData As String
        Dim message As String
        message = MsgBox("do you want to delete?", vbYesNo)
        If message = vbNo Then Exit Sub
        deleteData = "DELETE FROM table WHERE cust_id='" & Cust_IDTextBox.Text & "'"
        runSql(deleteData)

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.Close()

    End Sub

End Class

感谢您的善意和帮助!

0 个答案:

没有答案