473,804 Members | 3,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange Behavoir With OleDbDataAdapte r

Hi,

Hope someone can explain this...

OK, here is the simplest subset of my code that shows the problem:

I have a C# Method:

Private void UpdateDataTable (DataTable myDT)
{
OleDbCommand comm = new OleDbCommand();
comm.CommandTex t = "AddComponentsF orJobT";
comm.CommandTyp e = CommandType.Sto redProcedure;
OleDbConnection conn = new OleDbConnection (CONNECTION_STR ING);
conn.Open();
comm.Connection = conn;
comm.Parameters .Add("pPartNo", OleDbType.VarCh ar,10,"PartNo") .SourceVersion
= DataRowVersion. Current;
da.InsertComman d = comm;
da.Update(myDT) ;
}

An Access Query:

AddComponentsFo rJobT
=============== ===
PARAMETERS pPartNo Text ( 255 );
INSERT INTO PropJobParts ( PartNo )
SELECT [pPartNo] AS Expr2;

If I pass into the above method a DataTable containing 3 rows with a
RowState of 'Added'

PartNo
=====
AAA
BB
C

The code runs successfully, but what finished up in my Access table is:

AAA
BBA
CBA

Anyone tell me what I'm doing wrong or missing out??? It seems like the
Automagic stuff inside OledbDataAdapte r.Update that runs the Insert command
is not clearing the parameters between each subsequent insert.

Please!

Thanks,

Chris.
--
Remove Elvis's shoes to reply.
Jul 29 '05 #1
4 1602
Chris - the Automagic stuff is really just calling the Update command you
specify/or insert or delete and filling in the params for you. Are you sure
that the values that are in the params are correct? Also, if that's the
exact query, where are the params listed in the INsert statement? Typically
a ? is used for OleDb so you may be passing in a hard coded Sql Statement
which would possibly be the problem.

Let me know if not though and we'll take it from there.

"Chris Mayers" <ch************ **@SUEDEYahoo.C om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

Hope someone can explain this...

OK, here is the simplest subset of my code that shows the problem:

I have a C# Method:

Private void UpdateDataTable (DataTable myDT)
{
OleDbCommand comm = new OleDbCommand();
comm.CommandTex t = "AddComponentsF orJobT";
comm.CommandTyp e = CommandType.Sto redProcedure;
OleDbConnection conn = new OleDbConnection (CONNECTION_STR ING);
conn.Open();
comm.Connection = conn;

comm.Parameters .Add("pPartNo", OleDbType.VarCh ar,10,"PartNo") .SourceVersion
= DataRowVersion. Current;
da.InsertComman d = comm;
da.Update(myDT) ;
}

An Access Query:

AddComponentsFo rJobT
=============== ===
PARAMETERS pPartNo Text ( 255 );
INSERT INTO PropJobParts ( PartNo )
SELECT [pPartNo] AS Expr2;

If I pass into the above method a DataTable containing 3 rows with a
RowState of 'Added'

PartNo
=====
AAA
BB
C

The code runs successfully, but what finished up in my Access table is:

AAA
BBA
CBA

Anyone tell me what I'm doing wrong or missing out??? It seems like the
Automagic stuff inside OledbDataAdapte r.Update that runs the Insert
command
is not clearing the parameters between each subsequent insert.

Please!

Thanks,

Chris.
--
Remove Elvis's shoes to reply.

Jul 29 '05 #2
Hi,

Thanks for your response.

Not sure if I made it that clear, but the query I'm talking about is in an
MS-Access database. It is declared in the database, and referenced in my
code only by the query name, so I'm not passing any SQL from my code. (More
or less a stored procedure if it were SQL Server).
The parameter IS declared (in Access) as follows:
PARAMETERS pPartNo Text ( 255 );

So just to clarify it for me, the DataAdapter.Upd ate method takes each row
in the DataTable, determines if it is a newly added row, a changed row or a
deleted row, then calls the appropriate query on it passing the values from
that DataRow to the parameters, the field from the DataRow that is passed to
each parameter being declared in the Parameter.Add method.

I have looked at the DataTable that is being passed to the DataAdapter, and
the values in the DataRows are what I would expect them to be, ie, in this
example, 'AAA', 'BB', 'C' etc.

I am about to try building a simple DataTable by hand, and passing that to
the Update method, just to rule out any strangeness in the data that I'm
using. I'll post back here with my findings...

Thanks,

Chris.

"W.G. Ryan MVP" <Wi*********@no spam.gmail.com> wrote in message
news:um******** ******@tk2msftn gp13.phx.gbl...
Chris - the Automagic stuff is really just calling the Update command you
specify/or insert or delete and filling in the params for you. Are you sure that the values that are in the params are correct? Also, if that's the
exact query, where are the params listed in the INsert statement? Typically a ? is used for OleDb so you may be passing in a hard coded Sql Statement
which would possibly be the problem.

Let me know if not though and we'll take it from there.

"Chris Mayers" <ch************ **@SUEDEYahoo.C om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

Hope someone can explain this...

OK, here is the simplest subset of my code that shows the problem:

I have a C# Method:

Private void UpdateDataTable (DataTable myDT)
{
OleDbCommand comm = new OleDbCommand();
comm.CommandTex t = "AddComponentsF orJobT";
comm.CommandTyp e = CommandType.Sto redProcedure;
OleDbConnection conn = new OleDbConnection (CONNECTION_STR ING);
conn.Open();
comm.Connection = conn;

comm.Parameters .Add("pPartNo", OleDbType.VarCh ar,10,"PartNo") .SourceVersion = DataRowVersion. Current;
da.InsertComman d = comm;
da.Update(myDT) ;
}

An Access Query:

AddComponentsFo rJobT
=============== ===
PARAMETERS pPartNo Text ( 255 );
INSERT INTO PropJobParts ( PartNo )
SELECT [pPartNo] AS Expr2;

If I pass into the above method a DataTable containing 3 rows with a
RowState of 'Added'

PartNo
=====
AAA
BB
C

The code runs successfully, but what finished up in my Access table is:

AAA
BBA
CBA

Anyone tell me what I'm doing wrong or missing out??? It seems like the
Automagic stuff inside OledbDataAdapte r.Update that runs the Insert
command
is not clearing the parameters between each subsequent insert.

Please!

Thanks,

Chris.
--
Remove Elvis's shoes to reply.


Aug 1 '05 #3
OK,

To rule out any strangeness that may be being caused by the DataTable I'm
trying to update, I'm creating my own just for this test:

So:

private void CreateDataTable ()
{
DataTable dt = new DataTable();
dt.Columns.Add( "PartNo",Type.G etType("System. String"));
dt.Rows.Add(new string[]{"AAA"});
dt.Rows.Add(new string[]{"BB"});
dt.Rows.Add(new string[]{"C"});
UpdateDataTable (dt); // This is the method that is in my OP.
}

This still gives exactly the same problem, ie the data written into the
database is:
AAA
BBA
CBA

To (hopefully) reproduce the problem, you need a windows form with a button
that calls the above method,
plus the earlier method:

Private void UpdateDataTable (DataTable myDT)
{
OleDbCommand comm = new OleDbCommand();
comm.CommandTex t = "AddComponentsF orJobT";
comm.CommandTyp e = CommandType.Sto redProcedure;
OleDbConnection conn = new OleDbConnection (CONNECTION_STR ING);
conn.Open();
comm.Connection = conn;
comm.Parameters .Add("pPartNo", OleDbType.VarCh ar,10,"PartNo") .SourceVersion
= DataRowVersion. Current;
da.InsertComman d = comm;
da.Update(myDT) ;
}

plus an Access database containing a one table called 'PropJobParts' with a
single(text) field called 'PartNo'
And one update query called AddComponentsFo rJobT:

PARAMETERS pPartNo Text ( 255 );
INSERT INTO PropJobParts ( PartNo )
SELECT [pPartNo] AS Expr2;

If anyone has the time and the inclination to check this out, I would be
most grateful, I'm sure that I'm probably just missing somthing daft.

Thanks,

Chris.
"Chris Mayers" <ch************ **@SUEDEYahoo.C om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

Hope someone can explain this...

OK, here is the simplest subset of my code that shows the problem:

I have a C# Method:

Private void UpdateDataTable (DataTable myDT)
{
OleDbCommand comm = new OleDbCommand();
comm.CommandTex t = "AddComponentsF orJobT";
comm.CommandTyp e = CommandType.Sto redProcedure;
OleDbConnection conn = new OleDbConnection (CONNECTION_STR ING);
conn.Open();
comm.Connection = conn;

comm.Parameters .Add("pPartNo", OleDbType.VarCh ar,10,"PartNo") .SourceVersion = DataRowVersion. Current;
da.InsertComman d = comm;
da.Update(myDT) ;
}

An Access Query:

AddComponentsFo rJobT
=============== ===
PARAMETERS pPartNo Text ( 255 );
INSERT INTO PropJobParts ( PartNo )
SELECT [pPartNo] AS Expr2;

If I pass into the above method a DataTable containing 3 rows with a
RowState of 'Added'

PartNo
=====
AAA
BB
C

The code runs successfully, but what finished up in my Access table is:
AAA
BBA
CBA

Anyone tell me what I'm doing wrong or missing out??? It seems like the Automagic stuff inside OledbDataAdapte r.Update that runs the Insert
command
is not clearing the parameters between each subsequent insert.

Please!

Thanks,

Chris.
--
Remove Elvis's shoes to reply.



Aug 1 '05 #4
OK, looks like the fault is with MS-Access.

I've tried hard coding the query into the program, rather than calling an
Access Query,
ie I replaced:

comm.CommandTex t = "AddComponentsF orJobT";
comm.CommandTyp e = CommandType.Sto redProcedure;

in the code with:

comm.CommandTex t = "insert into propjobparts (partno) values(?)";
comm.CommandTyp e = CommandType.Tex t;

and it seems to work correctly.

OK,

To rule out any strangeness that may be being caused by the DataTable I'm
trying to update, I'm creating my own just for this test:

So:

private void CreateDataTable ()
{
DataTable dt = new DataTable();
dt.Columns.Add( "PartNo",Type.G etType("System. String"));
dt.Rows.Add(new string[]{"AAA"});
dt.Rows.Add(new string[]{"BB"});
dt.Rows.Add(new string[]{"C"});
UpdateDataTable (dt); // This is the method that is in my OP.
}

This still gives exactly the same problem, ie the data written into the
database is:
AAA
BBA
CBA

To (hopefully) reproduce the problem, you need a windows form with a button that calls the above method,
plus the earlier method:

Private void UpdateDataTable (DataTable myDT)
{
OleDbCommand comm = new OleDbCommand();
comm.CommandTex t = "AddComponentsF orJobT";
comm.CommandTyp e = CommandType.Sto redProcedure;
OleDbConnection conn = new OleDbConnection (CONNECTION_STR ING);
conn.Open();
comm.Connection = conn;
comm.Parameters .Add("pPartNo", OleDbType.VarCh ar,10,"PartNo") .SourceVersion = DataRowVersion. Current;
da.InsertComman d = comm;
da.Update(myDT) ;
}

plus an Access database containing a one table called 'PropJobParts' with a single(text) field called 'PartNo'
And one update query called AddComponentsFo rJobT:

PARAMETERS pPartNo Text ( 255 );
INSERT INTO PropJobParts ( PartNo )
SELECT [pPartNo] AS Expr2;

If anyone has the time and the inclination to check this out, I would be
most grateful, I'm sure that I'm probably just missing somthing daft.

Thanks,

Chris.
"Chris Mayers" <ch************ **@SUEDEYahoo.C om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
> Hi,
>
> Hope someone can explain this...
>
> OK, here is the simplest subset of my code that shows the problem:
>
> I have a C# Method:
>
> Private void UpdateDataTable (DataTable myDT)
> {
> OleDbCommand comm = new OleDbCommand();
> comm.CommandTex t = "AddComponentsF orJobT";
> comm.CommandTyp e = CommandType.Sto redProcedure;
> OleDbConnection conn = new OleDbConnection (CONNECTION_STR ING);
> conn.Open();
> comm.Connection = conn;
>
>

comm.Parameters .Add("pPartNo", OleDbType.VarCh ar,10,"PartNo") .SourceVersion
> = DataRowVersion. Current;
> da.InsertComman d = comm;
> da.Update(myDT) ;
> }
>
> An Access Query:
>
> AddComponentsFo rJobT
> =============== ===
> PARAMETERS pPartNo Text ( 255 );
> INSERT INTO PropJobParts ( PartNo )
> SELECT [pPartNo] AS Expr2;
>
> If I pass into the above method a DataTable containing 3 rows with a
> RowState of 'Added'
>
> PartNo
> =====
> AAA
> BB
> C
>
> The code runs successfully, but what finished up in my Access table is: >
> AAA
> BBA
> CBA
>
> Anyone tell me what I'm doing wrong or missing out??? It seems like the > Automagic stuff inside OledbDataAdapte r.Update that runs the Insert
> command
> is not clearing the parameters between each subsequent insert.
>
> Please!
>
> Thanks,
>
> Chris.
>
>
> --
> Remove Elvis's shoes to reply.
>
>



Aug 1 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1441
by: Markus Franz | last post by:
Hi. Today I created a script called load.py for using at the command line written in Python 2.3. This script should load as many websites as given on the comand line and print them with a seperation string to stdout. The loading was done in parallel. (I used processes for this.) The script was started by the following command:
1
475
by: jtsree | last post by:
I am Using (Windows XP) Visual Studio.net 2003 professional edition working on VB.net language. I am bulding a very very simple project in VB.net where i connect to Access Database by dragging OledbDataAdapter tool from the Data tab of the Toolbox. When OledbDataAdapter has been added to the Component tray i am able to generate a connection to Access database and generate Connection object and also the Test Connection has Succeeded. Now...
2
1441
by: Eyvind W Axelsen | last post by:
Hi. I am creating an application (primarily in C#), with MDI child windows. What I would like to do, is to override the default behavoir that makes a newly createad child form maximized if the topmost childform that already exists is also maximized. Furthermore, if I maximize one form, I don't want all the other forms to be maximized, and the same thing goes for 'restoring' forms to their original size. Any ideas?
24
4754
by: LineVoltageHalogen | last post by:
Greetings All, I was hoping that someone out there has run into this issue before and can shed some light on it for me. I have a stored procedure that essentially does a mini ETL from a source OLTP DB to a the target Operational Data Store. This is still in development so both DB's reside on the same machine for convenience. The stored proc runs successfully from within Query analyzer and this holds true on the following platforms: XP...
2
3821
by: Son Ha | last post by:
I want to copy some record from a Access database to another Access DB. My code as follow but not working. The destAdapter.Update() return 0 record affected. Tell me what's wrong in my code? public void CopyDataSet(int start, int end) { OleDbDataAdapter sourceAdapter = new OleDbDataAdapter("SELECT * FROM " + "WHERE ID > " + (start - 1).ToString() + " AND .id < " + (end + 1).ToString(), connectionString
1
5094
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);...
4
3989
by: shachar | last post by:
hi all(i tried yesterday but it didnt work). i wrote this code and i get an error msg: Private Pr_MyCon As System.Data.OleDb.OleDbConnection Private Pr_DataSet As DataSet Private Pr_DataAdapter As System.Data.OleDb.OleDbDataAdapter Pr_MyCon = New System.Data.OleDb.OleDbConnection Pr_DataSet = New DataSet("Temp") Pr_MyCon.ConnectionString = "..." Pr_DataAdapter = New OleDb.OleDbDataAdapter("select *
1
4797
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
4
293
by: Chris Mayers | last post by:
Hi, Hope someone can explain this... OK, here is the simplest subset of my code that shows the problem: I have a C# Method: Private void UpdateDataTable(DataTable myDT) {
0
9705
marktang
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...
0
9576
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,...
0
10567
Oralloy
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...
0
10323
jinu1996
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...
1
7613
isladogs
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...
0
6847
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();...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
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
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.