What's the easiest way to make an insert using Microsoft.Jet.O LEDB.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
PreparedStateme nt 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 2813
"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.O LEDB.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
PreparedStateme nt 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=Micro soft.Jet.OLEDB. 4.0" +
";Data Source=myFile.m db");
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.ExecuteNonQ uery();
connection.Clos e();
=============== =============== =========
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 of a performance hit I'm
taking using this technique versus using 'copy' to copy directly into a
container with elements in place?
Thanks,
d
|
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 procedure from SQL Server vs MS
Access point of view ?
|
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 is entered, either from a form or
from the table view of the table, when the record gets saved it
immediately displays #DELETED# in all of the fields. However, if I close
the form or table view and reopen the record has in fact been inserted.
The...
|
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 one-to-one relationship but on this
occasion
I must keep username/password details within a seperate table.
Here's the basic specs and database schema:
-------------------------------------------
|
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 :
INSERT INTO temp_tab VALUES (1,2,3)
| |
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 example I had to go by
'INSERT INTO tblCustomers (CustomerID, , )
|
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
using MS-Access 2000 database table for this app. Note that the
datatype of all the fields mentioned above are Text. Apart from the
above columns, there's another column in the DB table named
'RegDateTime' whose datatype is Date/Time which is...
|
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 common to ADOdb
$db = &ADONewConnection('access'); # create a connection
$db->PConnect('evdb'); # connect to MS-Access, evdb DSN
$db->debug = true;
//This code runs if the form has been submitted
|
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 (maybe QueryDefs?), so I wouldn't have to use the IDE and open Access to do it?
Here's more information if that helps: I can open Access itself and create a Query. I can save it and name it something meaningful. I can then execute that query just by...
|
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
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set the connection for database path
String Database_Path = "E:/Segi/Project/Coding/Car_Park_Storage.mdb";
|
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: 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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |