[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

HariNam Singh

3/18/2002 8:19:00 PM

Hi,

How are named parameters used? Below is my try, which brough the following
SQL error:

ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Must declare
the variable '@clientnumber'.

private const string SQL_INSERT = @"INSERT INTO ei_client_options
(clientnumber, taskmapping, deliverymethod, smtphost, emailto, emailreply,
emailcc, emailsubject, encrypted, aeskey, aesiv, transporthost,
transportport, created, createdby, updated, updatedby)
VALUES (@clientnumber, @taskmapping, @deliverymethod, @smtphost, @emailto,
@emailreply, @emailcc, @emailsubject, @encrypted, @aeskey, @aesiv,
@transporthost, @transportport, getdate(), @createdby, getdate(),
@updatedby)";

public void Insert(string currentUser) {
OdbcCommand command = Config.CreateOdbcCommand(SQL_INSERT);
command.Parameters.Add(new OdbcParameter("@clientnumber", ClientNumber));
command.Parameters.Add(new OdbcParameter("@taskmapping", TaskMapping));
command.Parameters.Add(new OdbcParameter("@deliverymethod",
DeliveryMethod));
command.Parameters.Add(new OdbcParameter("@smtphost", SmtpHost));
command.Parameters.Add(new OdbcParameter("@emailto", EmailTo));
command.Parameters.Add(new OdbcParameter("@emailreply", EmailReply));
command.Parameters.Add(new OdbcParameter("@emailcc", EmailCC));
command.Parameters.Add(new OdbcParameter("@emailsubject", EmailSubject));
command.Parameters.Add(new OdbcParameter("@encrypted", Encrypted));
command.Parameters.Add(new OdbcParameter("@aeskey", AesKey));
command.Parameters.Add(new OdbcParameter("@aesiv", AesIV));
command.Parameters.Add(new OdbcParameter("@transporthost", TransportHost));
command.Parameters.Add(new OdbcParameter("@transportport", TransportPort));
command.Parameters.Add(new OdbcParameter("@createdby", currentUser));
command.Parameters.Add(new OdbcParameter("@updatedby", currentUser));
Debug.WriteLine(command.CommandText);
command.ExecuteNonQuery();
command.Dispose();
}


thanks for improving my coding!


5 Answers

(David Sceppa)

3/18/2002 9:40:00 PM

0

HariNam Singh

3/18/2002 10:58:00 PM

0

That's what I used before. All method signatures to add a parameter required
a parameter name, where I put only dummy values, when using '?'. So, this
would be inconsistent between design and implementation.


"David Sceppa" <davidsc@online.microsoft.com> wrote in message
news:icvrH0rzBHA.1420@cpmsftngxa08...
>
> I believe the ODBC .NET Managed Provider only supports
> parameter markers. So the CommandText for your Command should
> look like this:
>
> "INSERT INTO MyTable (Col1, Col2, ...) VALUES (?, ?, ...)"
>
> I hope this information proves helpful.
>
> David Sceppa
> Microsoft
> This posting is provided "AS IS" with no warranties,
> and confers no rights. You assume all risk for your use.
> © 2002 Microsoft Corporation. All rights reserved.


(David Sceppa)

3/19/2002 2:54:00 AM

0

Daniel Naumann

3/19/2002 11:20:00 PM

0

And the order in which you add the parameters, has to match the order of you
markers. I don't think you need this with the SQL provider because they are
named.

Daniel.

"David Sceppa" <davidsc@online.microsoft.com> wrote in message
news:kp#63juzBHA.1876@cpmsftngxa07...
>
> You only use the parameter markers in the CommandText. When
> adding Parameter objects to the Command's Parameters collection,
> you give each Parameter object a unique name so you can access
> the item in the collection.
>
> David Sceppa
> Microsoft
> This posting is provided "AS IS" with no warranties,
> and confers no rights. You assume all risk for your use.
> © 2002 Microsoft Corporation. All rights reserved.


(David Sceppa)

3/20/2002 10:14:00 PM

0