mohdk_bh
Apr 26th, 2005, 01:46 PM
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
<%@ 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 :mad:
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
<%@ 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 :mad: