sg7qb Posted April 23, 2004 Posted April 23, 2004 hi, I have few problems with inserting data into access database using asp.net web form. what i am doing is that i am dropping a OleDbConnection and OleDbDataAdaptor to the web form and configuring to connect to the database. I am working on IIS Server on my personal Computer and the database is in the same folder where the asp file is stored . i have written the following code for adding records to the database table.the problem with the below code is that the new record is not getting added to database table. I dont know whether there is any problem with the connection or the code.Can any body help out with this ??? the code is Private Sub BtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click Me.OleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & Server.MapPath("Application.mdb") & ";" Me.OleDbSelectCommand1.CommandText = "SELECT * FROM ApplicationForm" Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1 Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1 Dim ds As New DataSet Me.OleDbDataAdapter1.Fill(ds, "ApplicationForm") Dim NewDataRow As DataRow = ds.Tables("ApplicationForm").NewRow NewDataRow("Date1") = TxtDate.Text NewDataRow("FirstName") = TxtFirstName.Text NewDataRow("LastName") = TxtLastName.Text NewDataRow("Address1") = TxtAddress1.Text NewDataRow("Address2") = TxtAddress2.Text NewDataRow("City") = TxtCity.Text NewDataRow("State") = TxtState.Text NewDataRow("ZipCode") = TxtZipCode.Text NewDataRow("Home1") = TxtHome1.Text NewDataRow("Home2") = TxtHome2.Text NewDataRow("Home3") = TxtHome3.Text NewDataRow("Work1") = TxtWork1.Text NewDataRow("Work2") = TxtWork2.Text NewDataRow("Work3") = TxtWork3.Text NewDataRow("Cell1") = TxtCell1.Text NewDataRow("Cell2") = TxtCell2.Text NewDataRow("Cell3") = TxtCell3.Text NewDataRow("Email") = TxtEmail.Text NewDataRow("DriverLicense") = TxtDriver.Text NewDataRow("Student") = RadioButtonList1.SelectedValue() NewDataRow("Smoke") = RadioButtonList6.SelectedValue() NewDataRow("SmokeYes") = TxtYesExplain.Text NewDataRow("Available") = RadioButtonList2.SelectedValue() NewDataRow("Charged") = RadioButtonList3.SelectedValue() NewDataRow("ChargedYes") = TxtOffense.Text NewDataRow("Learn") = TxtPosition.Text NewDataRow("Worked") = RadioButtonList4.SelectedValue() NewDataRow("WorkedYes") = TxtYesWorkedDis.Text NewDataRow("PreferMF") = RadioButtonList5.SelectedValue() NewDataRow("PreferFP") = RadioButtonList7.SelectedValue() NewDataRow("Sunday") = TxtMonday.Text NewDataRow("Tuesday") = TxtTuesday.Text NewDataRow("Wednesday") = TxtWednesday.Text NewDataRow("Thursday") = TxtThursday.Text NewDataRow("Friday") = TxtFriday.Text NewDataRow("Saturday") = TxtSaturday.Text NewDataRow("Comments") = TxtComment.Text NewDataRow("CheckList1") = CheckBoxList1.SelectedValue NewDataRow("CheckList2") = CheckBoxList2.SelectedValue ds.Tables("ApplicationForm").Rows.Add(NewDataRow) ds.AcceptChanges() OleDbDataAdapter1.Update(ds, "ApplicationForm") Me.OleDbConnection1.Close() End Sub Quote
fadi Posted April 23, 2004 Posted April 23, 2004 ur code seams fine, u can try 2 things, 1st try to use a datatable instead of a dataset, if this didnt work try in ur select statement to put all the fields preceeded by the [tablename][.] Quote
fadi Posted April 23, 2004 Posted April 23, 2004 no no no i got it u need to put the acceptchanges after the update Quote
sg7qb Posted April 23, 2004 Author Posted April 23, 2004 inserting data into database hi, i am getting the following error when i put acceptchanges() after Update() "Operation must use an updateable query" how can i solve that no no no i got it u need to put the acceptchanges after the update Quote
sg7qb Posted April 23, 2004 Author Posted April 23, 2004 Inserting Data in Access I am getting the following error when i put AcceptChanges after Update() 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 607: NewDataRow("CheckList2") = "1000" ' CheckBoxList2.SelectedValue Line 608: ds.Tables("ApplicationForm").Rows.Add(NewDataRow) Line 609: OleDbDataAdapter1.Update(ds, "ApplicationForm") Line 610: ds.AcceptChanges() Line 611: Me.OleDbConnection1.Close() Source File: c:\inetpub\wwwroot\WebApplication2\Application.aspx.vb Line: 609 Stack Trace: [OleDbException (0x80004005): Operation must use an updateable query.] System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) WebApplication2.WebForm1.BtnSubmit_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\WebApplication2\Application.aspx.vb:609 System.Web.UI.WebControls.Button.OnClick(EventArgs e) System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) System.Web.UI.Page.ProcessRequestMain() Please let me know where i am going wrong. Thanks no no no i got it u need to put the acceptchanges after the update Quote
wessamzeidan Posted April 23, 2004 Posted April 23, 2004 You have no insert query build your insert command like you did with your select command and give it to the dataadapter OleDbDataAdapter1.InsertCommand=Me.OleDbInsertCommand1 Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
fadi Posted April 23, 2004 Posted April 23, 2004 its much easier for u to build ur adapter using the wizard, or u can use a direct insert to the database without using a dataadapter, this would be preferrable Quote
sg7qb Posted April 26, 2004 Author Posted April 26, 2004 inserting records into access database hi, how can i do using dataadaptor. i tried to configure it by following the wizard. what do i need to do once i finish configuring that.do i still need to write the code which i wrote earlier in this thread. please tell me the steps to follow.... Thanks its much easier for u to build ur adapter using the wizard' date=' or u can use a direct insert to the database without using a dataadapter, this would be preferrable[/quote'] Quote
fadi Posted April 26, 2004 Posted April 26, 2004 once you use the wizard then u should not set the select command properties anymore since u should have set them in the wizard. everything should work fine from there Quote
joe_pool_is Posted October 25, 2004 Posted October 25, 2004 once you use the wizard then u should not set the select command properties anymore since u should have set them in the wizard. everything should work fine from thereWhat is the Wizard? Is this one of those tools built into Visual Studio .NET that I have never used? How do I get to it? Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.