Thursday, March 29, 2012

Setting Parameters

When setting parameters, I get the error:

System.IndexOutOfRangeException: Invalid index -1

With Me.MySqlCommand1
.Parameters("@dotnet.itags.org.FileName").Value = sFileName
.ExecuteNonQuery()
End With

The insert statement is:

INSERT INTO management (FileName) VALUES (@dotnet.itags.org.FileName)

Any ideas what's gone wrong?Hi,

You must create the parameter before setting its value, declaring the
parameter in the SQL query doesn't make it available in the Parameters
collection.

In C# this is somthing like this (I'm not familiar with VB.net) :

SqlParameter param=new SqlParameter("@.FileName",SqlDbType.String);
Param.Value = sFileName;
MySqlCommand1.Parameters.Add(param);
MySqlCommand1.ExecuteNonQuery();

Hope this will help you.

Kant

Le 7/08/05 13:07, dans A1BD4CD1-C0EA-44DB-9847-6A0567DAB30E@.microsoft.com,
*Niggy* <Niggy@.discussions.microsoft.com> a crit*:

> When setting parameters, I get the error:
> System.IndexOutOfRangeException: Invalid index -1
> With Me.MySqlCommand1
> .Parameters("@.FileName").Value = sFileName
> .ExecuteNonQuery()
> End With
>
> The insert statement is:
> INSERT INTO management (FileName) VALUES (@.FileName)
> Any ideas what's gone wrong?

0 comments:

Post a Comment