|
-
Apr 26th, 2005, 01:46 PM
#1
Thread Starter
Junior Member
Error: Operation must use an updateable query.
Hi everybody
I can tell that there we people who faced this problem before, please help if you know any solution..
when I try to add a record to the (Access) database using OledbCommand in Asp.net, it gives me the error: (Operation must use an updateable query. ).. but if i try the same code in Windows-based application it works fine... amazingly, it works too if using WebMatrix..
Do u have any clue..
the code I'm trying is
Code:
<%@ import Namespace="System.Data.Oledb" %>
<%@ import Namespace="System.Data" %>
<%@ Page Language="VB" %>
<HTML>
<HEAD>
<title>Reading from a database</title>
<script runat="server">
Dim con As OleDbConnection = New OleDbConnection
Dim comm As OleDbCommand = New OleDbCommand
' This subroutine is called when the page is loaded
Sub Page_Load (Sender As Object, E As EventArgs)
LoadGrid()
End Sub
' This subroutine is used to populate the datagrid
Sub LoadGrid()
Dim adaptor As OleDbDataAdapter = New OleDbDataAdapter
Dim patientDS As DataSet = New DataSet
con.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb"
comm.CommandText = "Select * From Patient"
comm.Connection = con
adaptor.SelectCommand = comm
adaptor.SelectCommand.Connection.Open
adaptor.Fill(patientDS, "Patient")
PatientTable.DataSource = patientDS.Tables("Patient")
PatientTable.DataBind
con.close()
End Sub
'This subroutine is called when a button is clicked
Sub cmdSubmit_Click (sender As Object, e As EventArgs)
Dim SQLtext as String
SQLText = "('" & txtFirst.Text & "','" & _
txtMiddle.Text & "'," & _
txtCPR.Text & ", '" & _
Gender.selectedItem.Value & "',#" & _
txtDOB.Text & "#)"
con.Open()
comm.CommandText = "INSERT INTO Patient VALUES " & _
SQLText
comm.Connection = con
comm.ExecuteNonQuery()
con.close()
ClearControls()
LoadGrid()
End Sub
'This subroutine is used to clear the text fields
Sub ClearControls()
txtFirst.Text = ""
txtMiddle.Text = ""
txtCPR.Text = ""
txtDOB.Text = ""
End Sub
</script>
</HEAD>
<body>
<h1>Patient Database
</h1>
<form runat="server" ID="Form1">
<p>
<asp:datagrid id="PatientTable" runat="server" border="5"></asp:datagrid>
</p>
<br>
<br>
<p>
Patient Name: First:
<asp:TextBox id="txtFirst" runat="server"></asp:TextBox>
Middle:
<asp:TextBox id="txtMiddle" runat="server"></asp:TextBox>
</p>
<p>
Patient Data: CPR:
<asp:TextBox id="txtCPR" runat="server"></asp:TextBox>
Date Of Birth:
<asp:TextBox id="txtDOB" runat="server"></asp:TextBox>
</p>
<p>
Gender
<asp:RadioButtonList id="Gender" runat="server">
<asp:listitem id="optMale" runat="server" value="Male" />
<asp:listitem id="optFemale" runat="server" value="Female" />
</asp:RadioButtonList>
</p>
<asp:Button id="cmdSubmit" onclick="cmdSubmit_Click" runat="server" Text="Add Record"></asp:Button>
</form>
</body>
</HTML>
This code works fine in WebMatrix.. but gives the error in Visual Studio .net..... please help
I'ts not so much where you stand in life, but in what direction you are moving
-
Apr 26th, 2005, 03:50 PM
#2
Addicted Member
Re: Error: Operation must use an updateable query.
lol, you say that your code works in a windows app.
Well, i had this error when starting to use Access in ASP.
Turn on your guest account (or at leat give your ASP.Net user account rights to your ASP.Net Application's folder). The problem occurs because your ASPNet user account doesn't have rights to your web application folder.
Let us know if this solves the problem.
g'luck
If the facts don't fit the theory, change the facts. --Albert Einstein
-
Apr 26th, 2005, 04:45 PM
#3
Thread Starter
Junior Member
Re: Error: Operation must use an updateable query.
 Originally Posted by Rockhopper
lol, you say that your code works in a windows app.
Turn on your guest account (or at leat give your ASP.Net user account rights to your ASP.Net Application's folder). The problem occurs because your ASPNet user account doesn't have rights to your web application folder.
Let us know if this solves the problem.
g'luck
Well thanks mate,
I tried and turned the guest acount, but still have the same problem.
I tried giving Asp.net Machine user account and administrative privilages,, but still have the problem...
but how can i give my ASP.Net user account rights to your ASP.Net Application's folder?
thank ya
I'ts not so much where you stand in life, but in what direction you are moving
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|