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 2573 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?
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.
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:
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);...
|
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);
|
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
|
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...
|
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
| |
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...
|
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...
|
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?
...
|
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...
|
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
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |