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! -
Public Sub InsertSvcReq(ByVal FormType As String, ByVal CustName As String, _
-
ByVal CustAdd As String, ByVal CustState As String, _
-
ByVal CustPostcode As String, ByVal CustPhone As String, _
-
ByVal CustFax As String, ByVal CustEmail As String, _
-
ByVal CustCRS As String, ByVal CustPrvRMA As String, _
-
ByVal PdtDetails As DataTable)
-
-
Dim con As OleDb.OleDbConnection = DBConnect.GetConnection()
-
-
Dim SqlCMD As String = "Select count(RMA_No) as RMANO from RMA where RMA_No like '" & FormType & "%'"
-
Dim myCMD As New OleDb.OleDbCommand(SqlCMD, con)
-
Dim DataReader As OleDb.OleDbDataReader = myCMD.ExecuteReader()
-
DataReader.Read()
-
-
Dim SvcNo As String = FormType & "/RCC/" & Now.ToString("yy") & "/" & format4digits(CInt(DataReader("RMANO")) + 1)
-
DataReader.Close()
-
-
SqlCMD = "insert into RMA values('" & SvcNo & "','" & Now & "','" & CustName & "','" _
-
& CustAdd & "','" & CustState & "','" & CustPostcode & "','" & CustPhone & "','" _
-
& CustFax & "','" & CustEmail & "','" & CustCRS & "','" & CustPrvRMA & "')"
-
-
myCMD.CommandText = SqlCMD
-
myCMD.ExecuteNonQuery()
-
-
PdtDetails.Columns.Remove("No.")
-
PdtDetails.AcceptChanges()
-
-
For i As Integer = 0 To PdtDetails.Rows.Count - 1
-
PdtDetails.Rows(i)("RMA_No") = SvcNo
-
Next
-
PdtDetails.AcceptChanges()
-
-
SqlCMD = "select * from RMA_Prod_Description"
-
-
Dim DataAdapter As New OleDb.OleDbDataAdapter(SqlCMD, con)Dim CmdBuilder As New OleDb.OleDbCommandBuilder(DataAdapter)
-
DataAdapter.InsertCommand = CmdBuilder.GetInsertCommand
-
-
DataAdapter.Update(PdtDetails)
-
-
End Sub
-
-
-
PS: The table I am working is manually created using the following code before passing it to the above method
-
-
Protected Sub CreateTable()
-
dtSvcReq.Columns.Add("No.", Type.GetType("System.Int16"))
-
-
-
dtSvcReq.Columns.Add("RMA_No", Type.GetType("System.String"))
-
dtSvcReq.Columns.Add("Product_Description", Type.GetType("System.String"))
-
dtSvcReq.Columns.Add("Serial_No", Type.GetType("System.String"))
-
dtSvcReq.Columns.Add("DOP", Type.GetType("System.String"))
-
dtSvcReq.Columns.Add("POP", Type.GetType("System.String"))
-
dtSvcReq.Columns.Add("Phy_Dmg", Type.GetType("System.Boolean"))
-
dtSvcReq.Columns.Add("Store_Replace", Type.GetType("System.Boolean"))
-
dtSvcReq.Columns.Add("Fault_Desc", Type.GetType("System.String"))
-
dtSvcReq.AcceptChanges()
-
Session("SvcReqCart") = dtSvcReq
-
End Sub
-
-
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
intSvcItem = Session("intSvcItem")
-
Dim tempDate As DateTime = txtDOP.Text
-
-
If intSvcItem < 5 Then
-
intSvcItem += 1
-
-
dtSvcReq = Session("SvcReqCart")
-
drSvcReq = dtSvcReq.NewRow
-
drSvcReq("No.") = intSvcItem
-
drSvcReq("Product_Description") = txtProduct.Text
-
drSvcReq("Serial_No") = txtSN.Text
-
drSvcReq("DOP") = tempDate.ToString("dd MMM yyyy")
-
drSvcReq("POP") = txtPOP.Text
-
drSvcReq("Phy_Dmg") = ddlPhysical_Dmg.SelectedValue
-
drSvcReq("Store_Replace") = ddlStore_Replace.SelectedValue
-
drSvcReq("Fault_Desc") = txtFaultDescription.Text
-
-
dtSvcReq.Rows.Add(drSvcReq)
-
dtSvcReq.AcceptChanges()
-
Session("SvcReqCart") = dtSvcReq
-
Session("intSvcItem") = intSvcItem
-
gvRMADetails.DataSource = dtSvcReq
-
gvRMADetails.DataBind()
-
Else
-
lblmsg.Text = "Reach maximum of 5 items per service request."
-
End If
-
End Sub
-
2 2525
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?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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:
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |