473,473 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with prepare statement during an Insert

Hi all,
I'm trying to do an insert using MySQL OleDb Provider.
I'd like to use the prepare() method of OleDbCommand class
to precompile the statement.
The problem is that when I issue prepare() I get an error
"OleDbCommand.Prepare requires all parameters to have an explicitly set
type"

I have checked the parameters and it seems to me that I didn't forget
anything....anybody can help me ?
Thanks a lot
here's my code:

System.Data.OleDb.OleDbConnection con;
con=new System.Data.OleDb.OleDbConnection("");
con.ConnectionString="Provider=MySqlProv.3.0;Data
Source=fad;Password=admin;User ID=admin";

try
{
con.Open();
OleDbCommand cmd = new OleDbCommand(null,con);

cmd.CommandText = "INSERT into ANAGRAFICA (ANAG_RS," +
"ANAG_INDIRIZZO,"+
"ANAG_CF," +
"ANAG_CAP," +
"ANAG_EMAIL," +
"ANAG_RIFERIMENTO," +
"ANAG_PHONE1," +
"ANAG_PHONE2)" +
" values ( " +
"@ANAG_RS," +
"@ANAG_INDIRIZZO," +
"@ANAG_CF," +
"@ANAG_CAP," +
"@ANAG_EMAIL," +
"@ANAG_RIFERIMENTO,"+
"@ANAG_PHONE1,"+
"@ANAG_PHONE2)";
cmd.Parameters.Add("@ANAG_RS" ,this.textRS.Text);
cmd.Parameters.Add ("@ANAG_INDIRIZZO" ,this.textIndirizzo.Text);

cmd.Parameters.Add ("@ANAG_CF" ,this.textCF.Text);
cmd.Parameters.Add ("@ANAG_CAP" , this.textCap.Text);
cmd.Parameters.Add ("@ANAG_EMAIL" , this.textMail.Text);
cmd.Parameters.Add ("@ANAG_RIFERIMENTO", this.textRiferimento.Text);

cmd.Parameters.Add ("@ANAG_PHONE1", this.textTelefono1.Text);
cmd.Parameters.Add ("@ANAG_PHONE2", this.textTelefono2.Text);
cmd.Prepare ( );
cmd.ExecuteNonQuery ( );

Nov 16 '05 #1
3 6776

<fm********@libero.it> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi all,
I'm trying to do an insert using MySQL OleDb Provider.
I'd like to use the prepare() method of OleDbCommand class
to precompile the statement.
The problem is that when I issue prepare() I get an error
"OleDbCommand.Prepare requires all parameters to have an explicitly set
type"

I have checked the parameters and it seems to me that I didn't forget
anything....anybody can help me ?
Thanks a lot
here's my code:
<<clipped>>
cmd.Parameters.Add("@ANAG_RS" ,this.textRS.Text);
cmd.Parameters.Add ("@ANAG_INDIRIZZO" ,this.textIndirizzo.Text);


You didn't provide a single OleDb data type on your cmd.Parameters.Add call.
See
http://msdn.microsoft.com/library/en...saddtopic6.asp
I'd expect these lines to read:
cmd.Parameters.Add("@ANAG_RS" ,OleDbType.VarChar, this.textRS.Text.Length,
this.textRS.Text);
cmd.Parameters.Add ("@ANAG_INDIRIZZO"
,OleDbType.VarChar,this.textIndirizzo.Text.Length, this.textIndirizzo.Text);

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Nov 16 '05 #2
you haven't set the parameter types when adding the parameters into the
collection, just as the exception says.

e.g.

myParamCollection.Add("CustomerID", OleDbType.VarChar)

HTH

Ollie Riches
<fm********@libero.it> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi all,
I'm trying to do an insert using MySQL OleDb Provider.
I'd like to use the prepare() method of OleDbCommand class
to precompile the statement.
The problem is that when I issue prepare() I get an error
"OleDbCommand.Prepare requires all parameters to have an explicitly set
type"

I have checked the parameters and it seems to me that I didn't forget
anything....anybody can help me ?
Thanks a lot
here's my code:

System.Data.OleDb.OleDbConnection con;
con=new System.Data.OleDb.OleDbConnection("");
con.ConnectionString="Provider=MySqlProv.3.0;Data
Source=fad;Password=admin;User ID=admin";

try
{
con.Open();
OleDbCommand cmd = new OleDbCommand(null,con);

cmd.CommandText = "INSERT into ANAGRAFICA (ANAG_RS," +
"ANAG_INDIRIZZO,"+
"ANAG_CF," +
"ANAG_CAP," +
"ANAG_EMAIL," +
"ANAG_RIFERIMENTO," +
"ANAG_PHONE1," +
"ANAG_PHONE2)" +
" values ( " +
"@ANAG_RS," +
"@ANAG_INDIRIZZO," +
"@ANAG_CF," +
"@ANAG_CAP," +
"@ANAG_EMAIL," +
"@ANAG_RIFERIMENTO,"+
"@ANAG_PHONE1,"+
"@ANAG_PHONE2)";
cmd.Parameters.Add("@ANAG_RS" ,this.textRS.Text);
cmd.Parameters.Add ("@ANAG_INDIRIZZO" ,this.textIndirizzo.Text);

cmd.Parameters.Add ("@ANAG_CF" ,this.textCF.Text);
cmd.Parameters.Add ("@ANAG_CAP" , this.textCap.Text);
cmd.Parameters.Add ("@ANAG_EMAIL" , this.textMail.Text);
cmd.Parameters.Add ("@ANAG_RIFERIMENTO", this.textRiferimento.Text);

cmd.Parameters.Add ("@ANAG_PHONE1", this.textTelefono1.Text);
cmd.Parameters.Add ("@ANAG_PHONE2", this.textTelefono2.Text);
cmd.Prepare ( );
cmd.ExecuteNonQuery ( );

Nov 16 '05 #3
thanks for your answers.
It's quite clear.
Regards
Francesco

Nov 16 '05 #4

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

Similar topics

0
by: Mike Chirico | last post by:
Hopefully this will help someone... Helpful Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Last Updated: Fri Apr 16 11:47:34 EDT 2004 The latest version of this...
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
6
by: Todd McNeill | last post by:
Hi- We ran into some very strange deadlocks this AM, and I was hoping to get some insight. We were running a REORGCHK on a database, and started getting deadlocks. What is curious is that...
2
by: claus.hirth | last post by:
I wrote a stored procedure that uses a prepared INSERT INTO statement in order to play with the PREPARE and EXECUTE keywords. In transcript 1 below the call to that stored procedure does not...
2
by: .Net Newbie | last post by:
Hello, I am somewhat new to .Net and currently working on an intranet site using C# going against SQL Server 2k. I am accepting personal information on a single webform and trying to insert the...
1
by: rAinDeEr | last post by:
Hi, I have started using DB2 UDB ESE v8.2 in Linux recently. I have seen a lot of articles on packages, prepare statement, bind and execute statement. I havent got a clear idea. I have...
0
by: Johan Neidenmark | last post by:
When i try to run this SQL statements in iSeries Access for windows (against my customers db2) i get: SQL State: 42904 Vendor Code: -7032 Message: SQL procedure, function, or trigger...
3
by: Rowan | last post by:
When I run a small test script I get the following error. ___________________________ PHP Fatal error: Call to a member function prepare() on a non-object in /usr/local/lib/php5/pg_connect.php on...
2
by: kya2 | last post by:
I am not able to create following store procedure. CREATE PROCEDURE DBSAMBA.InsertDeleteBatch(OUT norows INT ) RESULT SETS 1 LANGUAGE SQL BEGIN part1 DECLARE TOTAL_LEFT INT DEFAULT 0; ...
0
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,...
0
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,...
1
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...
0
tracyyun
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
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...

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.