Data Insert into Access Database

Grubber

New member
Joined
Nov 15, 2006
Messages
2
Programming Experience
1-3
VB.NET:
Imports System.Data.OleDb
Imports System.Data
PartialClass Registration
Inherits System.Web.UI.Page
Public strConn AsString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Server.MapPath("Andrewproject2.mdb")
 
ProtectedSub btnReg_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btnReg.Click
Dim dbconn AsNew OleDbConnection(strConn)
Dim sqlEmail, sqlAll AsString
sqlEmail = "SELECT Email FROM Members WHERE Email='" & txtREmail.Text & "'"
sqlAll = "INSERT INTO Members ([email], [Pass], [First Name], [Last Name], [Date of Birth]) VALUES ('" & txtREmail.Text & "', '" & txtRPass.Text & "', '" & txtFN.Text & "', '" & txtLN.Text & "', '" & txtDOB.Text & "')"
Dim dbcomEmail AsNew OleDbCommand(sqlEmail, dbconn)
Dim dbcomAll AsNew OleDbCommand(sqlAll, dbconn)
Dim Adapt AsNew OleDbDataAdapter("SELECT * FROM Members", dbconn)
Dim mydataset As DataSet = New DataSet("Insert")
Dim DataRow As DataRow
Adapt.InsertCommand = dbcomAll
dbconn.Open()
Adapt.Fill(mydataset)
 
Call Errorcheck()
Dim C AsString
C = "SELECT Email FROM Members WHERE Email='awgrubb@msn.com'"
Dim C1 AsNew OleDbCommand(C, dbconn)
If lblError.Text = ""Then
If dbcomEmail.ExecuteReader.Read = TrueThen
lblError.Text = "Sorry that email address is in use by another account."
dbconn.Close()
Else
Adapt.Fill(mydataset, "Members")
DataRow = mydataset.Tables("Members").NewRow()
DataRow(0) = txtREmail.Text
DataRow(1) = txtRPass.Text
DataRow(2) = txtFN.Text
DataRow(3) = txtLN.Text
DataRow(4) = txtDOB.Text
mydataset.Tables("Members").Rows.Add(DataRow)
Adapt.Update(mydataset, "Members")
mydataset.AcceptChanges()
dbconn.Close()
Response.Redirect("Events.aspx?name=" & System.Web.HttpUtility.UrlEncode(txtREmail.Text))
EndIf
EndIf
 
 
EndSub
This code works perfectly in .net but it wont run on the server heres the error:


Server Error in '/' Application.

Operation must use an updateable query.

[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]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. [/FONT]

[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Exception Details: System.Data.OleDb.OleDbException: Operation must use an updateable query.
[/FONT]

[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]I have fooled around with this error for about a week now and its for a school project/real world client so i need to figure it out... Thanks for any possible help[/FONT]
 
Last edited by a moderator:
Your INSERT statement has no parameters so it cannot be used to save the contents of a DataTable to the database. The parameters are what determine how the data from the DataTable will map to the columns in the database table. No parameters means no mapping so no saving. I suggest that you read up about the OleDbParameter class.
 
Back
Top