none
接近 ')' 之處的語法不正確。 RRS feed

  • 問題

  •  Function ExecuteSQL(ByVal strSQL As String) As Integer
        Dim objCon As SqlConnection
        Dim objCmd As SqlCommand
        Dim intRowsAffected As Integer
        Dim strDbCon As String
        strDbCon = "Data Source=(local)\SQLExpress;" & _
        "AttachDbFilename=|DataDirectory|\停車場.mdf;" & _
        "Integrated Security=SSPI;" & _
        "User Instance=true"
        objCon = New SqlConnection(strDbCon) '建立Connection物件開啟資料庫連結
        objCon.ConnectionString = strDbCon
        objCon.Open()
        objCmd = New SqlCommand(strSQL, objCon) '建立Command物件
        '執行SQL指令
        intRowsAffected = objCmd.ExecuteNonQuery()  <strong><-----發生問題處</strong>
    
       '可以使用ExecuteNonQuery()方法執行建構子参數SQL指令
        objCon.Close()
        Return intRowsAffected
      End Function
    
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strSQL As String
        Dim intRowsAffected As Integer '建立SQL敘述新增一筆資料表紀錄
        strSQL = "INSERT INTO 客戶資料"
        strSQL &= "VALUES('" & TextBox1.Text & "','"
        strSQL &= TextBox2.Text & "','"
        strSQL &= TextBox3.Text & "','"
        strSQL &= TextBox4.Text & "','"
        strSQL &= TextBox5.Text & "','"
        strSQL &= TextBox6.Text & "','"
        strSQL &= TextBox7.Text & "')"
        intRowsAffected = ExecuteSQL(strSQL) '執行SQL
        MsgBox("已新增使用者 !!" & intRowsAffected)
      End Sub
    End Class
    

    2010年12月11日 下午 07:29

解答

所有回覆