ผมลองรันบน Microsoft Visual Web Developer 2005 แล้วสามารถติดต่อกับ Database ได้ ไม่มีปัญหา แต่พอผมรันบน IIS " http://192.168.100.33" ที่จำลแงขึ้นมาแล้วรันไม่ได้ครับ จะขึ้น Error ที่บรรทัด "com.ExecuteNonQuery()" รบกวนดูด code ให้ด้วยครับ ขอบคุณทุกๆคำตอบนะครับ Code ตามด้านล่างนี้ครับ
Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.OleDb
Partial Class Comments
Inherits System.Web.UI.Page
Protected Sub cmdSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/App_Data/GuestBook.mdb") & ";"
Dim Conn As New OleDbConnection(strConn)
Conn.Open()
Dim sqlAdd As String
sqlAdd = "INSERT INTO Guestbook (FullName, URL,Email,Comments) "
sqlAdd &= " VALUES ('" & txtFullName.Text & "',"
sqlAdd &= "'" & DropDownList1.SelectedItem.Text & "',"
sqlAdd &= "'" & txtEmail.Text & "',"
sqlAdd &= "'" & txtComments.Text & "')"
Dim com As New OleDbCommand(sqlAdd, Conn)
com.ExecuteNonQuery()
Conn.Close()
Response.Redirect("Default.aspx")
End Sub
Protected Sub cmdClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdClear.Click
txtFullName.Text = ""
txtURL.Text = "http://"
txtEmail.Text = ""
txtComments.Text = ""
End Sub
End Class
Server Error in '/' Application.
--------------------------------------------------------------------------------
Operation must use an updateable query.
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.OleDb.OleDbException: Operation must use an updateable query.
Source Error:
Line 23:
Line 24: Dim com As New OleDbCommand(sqlAdd, Conn)
Line 25: com.ExecuteNonQuery()
Line 26: Conn.Close()
Line 27: