I’m copying data across from an Access database to an MSDE database through
the use of some vb.net code.
Unfortunately the application crashes when it goes to copy across data, in
particular surnames that have an apostrophe such as O’Shay etc.
Also I have a ‘date/time’ value in my Access database that I have to copy
across to my MSDE database in a field that is of datatype ‘datetime’ and
length ‘8’. How do I get this right I tried to get this working and the page
would crash every time.
The code I’m using is as follows.
Dim conAuthors As OleDbConnection
Dim cmdSelectAuthor s As OleDbCommand
Dim dtrAuthors As OleDbDataReader
Dim txt_RC_TITLE, txt_RC_GIVENNAM E, txt_RC_SURNAME, txt_RC_MOBILE,
txt_RC_EMAIL, txt_RC_GROUPS as Object
Dim dte_RC_DATESTAM P as object 'the dte_RC_DATESTAM P is a datestamp that is
in the Access database that I have to copy across but I’m having a lot of
trouble not sure how to do it
'open Access database with customer details
conAuthors = New OleDbConnection ("PROVIDER=Micr osoft.Jet.OLEDB .4.0;DATA
Source=C:\Custo merDatabase.mdb ")
conAuthors.Open ()
cmdSelectAuthor s = New OleDbCommand( "Select * From CUSTOMERTABLE",
conAuthors )
dtrAuthors = cmdSelectAuthor s.ExecuteReader ()
'loop through all customer details in Access database, copy these details to
a new set of two tables in the MSDE database
While dtrAuthors.Read ()
'set up read in values from Access database
txt_RC_TITLE = dtrAuthors( "txtTITLE" )
txt_RC_GIVENNAM E = dtrAuthors( "txtGIVENNA ME" )
txt_RC_SURNAME = dtrAuthors( "txtSURNAME " )
txt_RC_MOBILE = dtrAuthors( "txtMOBILE" )
txt_RC_EMAIL = dtrAuthors( "txtEMAIL" )
'dte_RC_DATESTA MP = dtrAuthors( "dteDATESTA MP" )
'insert details into CUSTOMERDETAILS table in MSDE database and get that
intCUSID(custom er id) that is a unique integer that is created for each
record that is inserted into the table
Dim conDB As SqlConnection
Dim strInsert As String
Dim cmdInsert As SqlCommand
conDB = New
SqlConnection(" SERVER=xxx.xxx. xxx.xxx;UID=sa; PWD=xxxx;DATABA SE=customerdb")
strInsert = "Insert into CUSTOMERDETAILS (txtTITLE, txtGIVENNAME,
txtSURNAME, txtMOBILEPHONE) Values ('" & txt_RC_TITLE & "', '" &
txt_RC_GIVENNAM E & "', '" & txt_RC_SURNAME & "', '" & txt_RC_MOBILE & "');
SELECT SCOPE_IDENTITY( )"
cmdInsert = New SqlCommand(strI nsert, conDB)
conDB.Open()
Dim intCUSID As Integer
intCUSID = cint(cmdInsert. ExecuteScalar() )
conDB.Close()
'Add the customers email address and the intCUSID(custom er id) to the
CUSMARKETING table
Dim strConn As String =
"SERVER=xxx.xxx .xxx.xxx;UID=sa ;PWD=xxxx;DATAB ASE=customerdb"
Dim cmd As New SqlCommand("INS ERT INTO CUSMARKETING (intCUSID,
txtEMAILADDRESS ) VALUES('" & intCUSID & "', '" & txt_RC_EMAIL & "')", New
SqlConnection(s trConn))
cmd.Connection. Open()
cmd.ExecuteNonQ uery()
cmd.Connection. Close()
End While
dtrAuthors.Clos e()
conAuthors.Clos e() 1 2760
I highly recommend using parameterized SQL statements. I believe this
will fix most of your problems.
Example:
Dim cn As New SqlConnection(s trConn)
Try
cn.Open()
Dim cmd As New SqlCommand("INS ERT INTO CUSMARKETING (intCUSID,
txtEMAILADDRESS ) SELECT @intCUSID, @txtEMAILADDRES S", cn)
cmd.Parameters. Add("@intCUSID" , intCUSID)
cmd.Parameters. Add("@txtEMAILA DDRESS", txt_RC_EMAIL)
cmd.ExecuteNonQ uery()
Finally
cn.Close()
End Try This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Martin |
last post by:
Hello,
I'm new with triggers and I can not find any good example on how to
do the following:
I have two tables WO and PM with the following fields:
WO.WONUM, VARCHAR(10)
WO.PMNUM, VARCHAR(10)
WO.PROBLEMCODE, VARCHAR(8)
|
by: Jassim Rahma |
last post by:
Hi,
I am using C# to insert a date value from the DatePicker into a DateTime
filed in mySQL database.. I am using the following syntax:
'" + datePicker.Value + "'
I also triend it withour the ' and with #
|
by: Tim::.. |
last post by:
Can someone please help! I'm trying to write an insert statement for a
complex datagrid! The database consists of the following data structure!
..tblContent
PageID PK
ModDate
Description
Title
..tblOffice
|
by: Matthias De Ridder |
last post by:
Hello,
I really hope that someone will be able to help me, because I'm desperate now!
I'm a student, graduating this year, and I'm working on a thesis where C#
Web Services are involved. I only have three weeks to finish it all!
My GUI and Web services were finished, but I hadn't tested them. So I linked
the GUI to the Web service and started testing them.
|
by: brianbasquille |
last post by:
Hello all,
Strange little problem here... am just trying to insert some basic
information into an Access Database using OleDB.
I'm getting a "Syntax error in Insert Into statement" when it tries to
execute the SQL. The strange thing is if i take the exact SQL being
executed from the debugger and insert and execute it using the MS
Access query engine, it works fine!
| |
by: Arpan |
last post by:
A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int
column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB"
(datetime). Now when I am trying to add a new row using the following
INSERT statement:
sqlDapter.InsertCommand = New SqlCommand
sqlDapter.InsertCommand.CommandText = "INSERT INTO UserDetailss
VALUES('bobby','simpson','" & Now() & "')"
sqlDapter.InsertCommand.Connection = sqlConn
sqlDapter.Update(dSet,...
|
by: dave k |
last post by:
I often use the Control and Apostrophe keys to enter the value from the
same field of the previous record in a form. I would prefer to use a
mouse and the double click function. Can anyone help please with the
programming language to type in the Double Click Event procedure
section.
I hope this is clear enough. Many thanks.
Dave k
|
by: DavidOwens |
last post by:
<form action="do.php" method="post">
<?php
/*
create table users (id int, staffid int, region varchar(20), firstname varchar(20), surname varchar(20));
insert into users values(1,1,'region1','John', 'Doe'),(2,2,'region1','Pete', 'Mackay');
create table stores (name varchar(10));
insert into stores values('Name1'),('Name2'),('Name3'),('Name4'),('Na me5'),('Name6');
*/
$con = mysql_connect("localhost","root","password");
|
by: BenRatcliffe |
last post by:
Hi there,
I was wondering if anyone could help me. I have a comlpex database with a number of forms that have data entered on them and then saved into the correct table etc. In this instance I am trying to get the data on a form to save the data in the current table where it is stored, insert the data into 2 new tables all on a click event. I have got the first 2 tables to update fine but the third I am having difficulty with.
The third...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: 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: 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...
|
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
| |