473,782 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OleDBDataAdapte r.Update does not work

3 New Member
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 2572
Plater
7,872 Recognized Expert Expert
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
kendrick82
3 New Member
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.Accept Changes() in btnAdd_Click() and InsertSvcReq() methods.

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

Cause:
When calling dtSvcReq.Accept Changes() before DataAdapter.Upd ate(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
5093
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: dsLocalDataSet.user_postRow newRow = dsLocalDataSet1.user_post.Newuser_postRow(); newRow.post_text = this.lblHiddenMessageStorage.Text; newRow.post_datetime = System.DateTime.Now; dsLocalDataSet1.user_post.Adduser_postRow(newRow);...
9
5279
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 INTO Table ( ID, Cod, CodArt, Q1, DataUscita ) VALUES (pID, pCod, pCod, pQ1, pDataUscita);
0
5827
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 which indexes computer magazine articles for personal reference. I am developing a Visual Basic.NET program whose sole purpose is to enter new records into the database. No updates to existing entries, no deletions, and no display
2
4400
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 against a SelectCommand that does not return any key column information.". Does any one know what I am missing? My codes look like this: ' Where the connection string is "Provider=Microsoft.Jet.OLEDB.4.0;Data...
1
4793
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 the field ends up with only a date, with no time component. In my project... I added an OleDBDataAdapter using the wizzard to my form. I generated the DataSet and added the desired table. I verified the field type in the
6
14914
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 would like to write the new ControlDate or Version into the database. First i update the dataset, then i create a Insertcommand and call the update-methode. All datas are in the database, but.... 1.) If I only use the InsertCommand, without...
1
1677
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, video, etc.). I am using an OleDbDataReader to retrieve a single record at a time from the source DB. I copy the retrieved values to a DataSet and then use an OleDbDataAdapter to insert the new row into the destination DB. This appears to work fine...
6
1868
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 insert statement in the two adapters, the adapter created with the wizard works fine, but the adapter created in code gives me an error "Object reference not set to an instance of an object". The code is below. What am I doing wrong? ...
2
1727
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 another Excel file) But if I run the same dll (tlb) from MS Access - I get an error that I need to use an updateable query. Why does the following code work fine in Excel but not in MS Acces? Maybe because Excel doesn't use Jet? Any...
6
1682
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 also created oledb connections to both data sources. Below is my attempt at achieving this, which doesn't work. I've
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9944
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.