What's the easiest way to make an insert using Microsoft.Jet.OLEDB.4.0
OleDbConnection connection to a MS Access data base file?
I'm finding examples out on the net that have like 1,000 line of code to
perform what I would imagine should be a very simple task.
I've mostly done DB code in Java and it would be simply making a
PreparedStatement with the wild cards inside, like:
"insert into MyTable (my_id, my_text) values (?, ?)"
and then using the various setObject(int position, object value) methods to
set the wildcards.... simple!
is there something as simple in C#?
I'm finding example codes creating these DataAdapters and setting these long
verbose Paramters and I'm getting really confused... 3 2789
"MrNobody" wrote...
I haven't seen anyone answering this, so I'll give it a shot...
What's the easiest way to make an insert using
Microsoft.Jet.OLEDB.4.0 OleDbConnection connection
to a MS Access data base file?
I'm finding examples out on the net that have like 1,000
line of code to perform what I would imagine should be a
very simple task.
It *is* a very simple task, but I guess most examples you've found are
focusing on the benefits of using DataSets.
I've mostly done DB code in Java and it would be simply making a
PreparedStatement with the wild cards inside, like:
"insert into MyTable (my_id, my_text) values (?, ?)"
and then using the various setObject(int position, object value) methods
to set the wildcards.... simple!
is there something as simple in C#?
Almost as simple.
I'm finding example codes creating these DataAdapters and setting these
long
verbose Paramters and I'm getting really confused...
The verbosity is greater in C#/ADO.NET than in Java, but not by much.
/// Just as in Java, you'll need to instantiate
/// and open a Connection
OleDbConnection connection =
new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0" +
";Data Source=myFile.mdb");
connection.Open();
/// Then create a Command (almost equivalent to a
/// a Java Statement), providing the SQL-string and
/// the connection.
OleDbCommand cmd =
new OleDbCommand
("insert into MyTable (my_id, my_text) values (:p_id, :p_text)",
connection);
/// Instead of the Java "setThings", you Add parameters with the
/// values you want.
cmd.Parameters.Add(new OleDbParameter("p_id", 7) );
cmd.Parameters.Add(new OleDbParameter("p_text", "the_text") );
/// And execute...
cmd.ExecuteNonQuery();
connection.Close();
=======================================
Of course there are many more variants of this, but maybe this can be a
start.
/// Bjorn A
Hi,
OleDbCommand cmd =
new OleDbCommand
("insert into MyTable (my_id, my_text) values (:p_id, :p_text)",
connection);
/// Instead of the Java "setThings", you Add parameters with the
/// values you want.
cmd.Parameters.Add(new OleDbParameter("p_id", 7) );
cmd.Parameters.Add(new OleDbParameter("p_text", "the_text") );
I had never seen this way to express the name of the parameters, have u
tested it?
I know of two: , anonymous, like
new OleDbCommand
("insert into MyTable (my_id, my_text) values ( ?, ?)",
connection);
and then the order of the parameters decide what goes where
and using @
new OleDbCommand
("insert into MyTable (my_id, my_text) values ( @id, @text)",
connection);
"Ignacio Machin ( .NET/ C# MVP )" wrote...
>OleDbCommand cmd = new OleDbCommand ("insert into MyTable (my_id, my_text) values (:p_id, :p_text)", connection);
/// Instead of the Java "setThings", you Add parameters with the /// values you want.
cmd.Parameters.Add(new OleDbParameter("p_id", 7) ); cmd.Parameters.Add(new OleDbParameter("p_text", "the_text") );
I had never seen this way to express the name of the parameters,
have u tested it?
Yep!
I know of two: , anonymous, like
new OleDbCommand
("insert into MyTable (my_id, my_text) values ( ?, ?)",
connection);
and then the order of the parameters decide what goes where
and using @
new OleDbCommand
("insert into MyTable (my_id, my_text) values ( @id, @text)",
connection);
That makes three... ;-)
I'm accustomed to the Oracle way of using parameters, so when I made some
stubs a couple of years ago, I wanted them to work against both Oracle and
Access...
And yes, it works! :-)
I guess it's a question of built in compatibility with different paradigms
where it doesn't collide with other syntactical elements, so I guess they
allow both ?, @ and :
/// Bjorn A This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: deancoo |
last post by:
I have gotten into the habit of often using copy along with an insert
iterator. There are scenarios where I process quite a lot of data this way.
Can someone give me a general feel as to how much...
|
by: ImraneA |
last post by:
Hi there
I had pleasure of upsizing Access v97 db to Access v2K/SQL 2K.
Wish to provide some knowledge gained back to community - hopefully
help others.
1.Question how do you test stored...
|
by: Bri |
last post by:
Greetings,
I'm having a very strange problem in an AC97 MDB with ODBC Linked tables
to SQL Server 7. The table has an Identity field and a Timestamp field.
The problem is that when a new record...
|
by: Carl |
last post by:
Hi,
I hope someone can share some of their professional advice and help me out
with my embarissing problem concerning an Access INSERT query. I have never
attempted to create a table with...
|
by: Geoffrey KRETZ |
last post by:
Hello,
I'm wondering if the following behaviour is the correct one for
PostGreSQL (7.4 on UNIX).
I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching
the following request :...
|
by: MP |
last post by:
Hi
Posted this several hours ago to another ng but it never showed up thought
i'd try here.
using vb6, ado, .mdb, jet4.0, no access
given table tblJob with field JobNumber text(10)
'The...
|
by: rn5a |
last post by:
During registration, users are supposed to enter the following
details: First Name, Last Name, EMail, UserName, Password, Confirm
Password, Address, City, State, Country, Zip & Phone Number. I am...
|
by: Zuggy |
last post by:
I'm trying to create a registration/login script using Access 2003. I'm using ADOdb to connect through ODBC.
<?php
// Connects to your Database
include('adodb/adodb.inc.php'); # load code...
|
by: DonnaL |
last post by:
I'm using Access 2000, but this question likely pertains to any version of Access. Simply put, is there a programmatic way of inserting a new Query in whatever master system table stores these...
|
by: yeap |
last post by:
Hi All,
I can't insert java variable into ms access database.
I'm using odbc connection to ms access.
Below are my coding.
try
{
...
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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: 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,...
|
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...
|
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...
| |