473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

OleDBDataAdapter.Update does not work

Hi, I am developing a web application and facing a difficulty in inserting the new data in a Datatable into the MS Access databse. The below method is able to execute without any error message but the data is not insert into the database. Please assists. Need to solve this urgently. Thanks!

Expand|Select|Wrap|Line Numbers
  1. Public Sub InsertSvcReq(ByVal FormType As String, ByVal CustName As String, _ 
  2. ByVal CustAdd As String, ByVal CustState As String, _
  3. ByVal CustPostcode As String, ByVal CustPhone As String, _ 
  4. ByVal CustFax As String, ByVal CustEmail As String, _
  5. ByVal CustCRS As String, ByVal CustPrvRMA As String, _ 
  6. ByVal PdtDetails As DataTable) 
  7.  
  8. Dim con As OleDb.OleDbConnection = DBConnect.GetConnection()
  9.  
  10. Dim SqlCMD As String = "Select count(RMA_No) as RMANO from RMA where RMA_No like '" & FormType & "%'"
  11. Dim myCMD As New OleDb.OleDbCommand(SqlCMD, con)
  12. Dim DataReader As OleDb.OleDbDataReader = myCMD.ExecuteReader() 
  13. DataReader.Read()
  14.  
  15. Dim SvcNo As String = FormType & "/RCC/" & Now.ToString("yy") & "/" & format4digits(CInt(DataReader("RMANO")) + 1) 
  16. DataReader.Close()
  17.  
  18. SqlCMD = "insert into RMA values('" & SvcNo & "','" & Now & "','" & CustName & "','" _
  19. & CustAdd & "','" & CustState & "','" & CustPostcode & "','" & CustPhone & "','" _ 
  20. & CustFax & "','" & CustEmail & "','" & CustCRS & "','" & CustPrvRMA & "')"
  21.  
  22. myCMD.CommandText = SqlCMD
  23. myCMD.ExecuteNonQuery()
  24.  
  25. PdtDetails.Columns.Remove("No.") 
  26. PdtDetails.AcceptChanges()
  27.  
  28. For i As Integer = 0 To PdtDetails.Rows.Count - 1 
  29. PdtDetails.Rows(i)("RMA_No") = SvcNo
  30. Next
  31. PdtDetails.AcceptChanges()
  32.  
  33. SqlCMD = "select * from RMA_Prod_Description"
  34.  
  35. Dim DataAdapter As New OleDb.OleDbDataAdapter(SqlCMD, con)Dim CmdBuilder As New OleDb.OleDbCommandBuilder(DataAdapter) 
  36. DataAdapter.InsertCommand = CmdBuilder.GetInsertCommand
  37.  
  38. DataAdapter.Update(PdtDetails)
  39.  
  40. End Sub
  41.  
  42.  
  43. PS: The table I am working is manually created using the following code before passing it to the above method
  44.  
  45. Protected Sub CreateTable()
  46.         dtSvcReq.Columns.Add("No.", Type.GetType("System.Int16"))
  47.  
  48.  
  49.         dtSvcReq.Columns.Add("RMA_No", Type.GetType("System.String"))
  50.         dtSvcReq.Columns.Add("Product_Description", Type.GetType("System.String"))
  51.         dtSvcReq.Columns.Add("Serial_No", Type.GetType("System.String"))
  52.         dtSvcReq.Columns.Add("DOP", Type.GetType("System.String"))
  53.         dtSvcReq.Columns.Add("POP", Type.GetType("System.String"))
  54.         dtSvcReq.Columns.Add("Phy_Dmg", Type.GetType("System.Boolean"))
  55.         dtSvcReq.Columns.Add("Store_Replace", Type.GetType("System.Boolean"))
  56.         dtSvcReq.Columns.Add("Fault_Desc", Type.GetType("System.String"))
  57.         dtSvcReq.AcceptChanges()
  58.         Session("SvcReqCart") = dtSvcReq
  59.     End Sub
  60.  
  61.     Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  62.         intSvcItem = Session("intSvcItem")
  63.         Dim tempDate As DateTime = txtDOP.Text
  64.  
  65.         If intSvcItem < 5 Then
  66.             intSvcItem += 1
  67.  
  68.             dtSvcReq = Session("SvcReqCart")
  69.             drSvcReq = dtSvcReq.NewRow
  70.             drSvcReq("No.") = intSvcItem
  71.             drSvcReq("Product_Description") = txtProduct.Text
  72.             drSvcReq("Serial_No") = txtSN.Text
  73.             drSvcReq("DOP") = tempDate.ToString("dd MMM yyyy")
  74.             drSvcReq("POP") = txtPOP.Text
  75.             drSvcReq("Phy_Dmg") = ddlPhysical_Dmg.SelectedValue
  76.             drSvcReq("Store_Replace") = ddlStore_Replace.SelectedValue
  77.             drSvcReq("Fault_Desc") = txtFaultDescription.Text
  78.  
  79.             dtSvcReq.Rows.Add(drSvcReq)
  80.             dtSvcReq.AcceptChanges()
  81.             Session("SvcReqCart") = dtSvcReq
  82.             Session("intSvcItem") = intSvcItem
  83.             gvRMADetails.DataSource = dtSvcReq
  84.             gvRMADetails.DataBind()
  85.         Else
  86.             lblmsg.Text = "Reach maximum of 5 items per service request."
  87.         End If
  88.     End Sub
  89.  
Jan 14 '08 #1
2 2525
Plater
7,872 Expert 4TB
I think the .Update() function looks for an UPDATE command that would be supplied to the datatable/dataset.
I see you created an INSERT function, but I did not see an UPDATE function.
Maybe that has to do with it?
Jan 15 '08 #2
Hi Plater, sorry for the late reply and thanks for the advice. :)

I had solved the problem few minutes ago. It was caused by the dtSvcReq.AcceptChanges() in btnAdd_Click() and InsertSvcReq() methods.

Once I removed all the dtSvcReq.AcceptChanges(), it is able to work properly.

Cause:
When calling dtSvcReq.AcceptChanges() before DataAdapter.Update(PdtDetails), the Rowstate of dtSvcReq will become Unchange and it will not update to the database.
Jan 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bennett Haselton | last post by:
Suppose I add a new row to a table in a dataset, and then I use an OleDbDataAdapter to add that new row to a SQL Server database using OleDbDataAdapter.Update(), as in the following code: ...
9
by: joun | last post by:
Hi all, i'm using this code to insert records into an Access table from asp.net, using a stored procedure, called qry_InsertData: PARAMETERS Long, Long, Text(20), Long, DateTime; INSERT...
0
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
2
by: Zuy Tran | last post by:
I'm trying to update my data source using the Update method in OleDbDataAdapter with automatic command generation and I got error "Dynamic SQL generation for the UpdateCommand is not supported...
1
by: RML | last post by:
Hi everyone, I am using VB.NET 2003 and an OleDBDataAdapter to update an Access table's DateTime field. The field's format is set to "General Date" (ie: 11/24/2004 8:00:00 AM). The problem is...
6
by: Marcel Hug | last post by:
Hi all ! I have a table in my database, which has 3 attributes. IDFailureControl, ControlDate and ControlVersion. In the following function I test, if the date of today allready exists. Then I...
1
by: Mary W via DotNetMonster.com | last post by:
I have an application that is reading a database table and "copying" the data to the identical table in another database. This table contains a field of type OLE Object (which contains image,...
6
by: tom c | last post by:
I create 2 data OleDbDataAdapters, one with the wizard, and one in code. I know the adapter created in code is OK because I use it to fill a data table. However, when I try to use the same SQL...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, I created a simple dll in VB2005 to use ADO.Net -- oleDBDataAdapter to write data to an Excel file. The code (below) works fine from an Excel file (invoke the dll from Excel to write to...
6
by: baldrick | last post by:
Hello, I am trying to plonk the entire contents of a dBase file into an Access table. I have scanned the dBase fields and created an empty Access table with the same field formats. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.