473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Setting Parameters

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?
Nov 19 '05 #1
1 1189
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 A1**********************************@microsoft.com,
«*Niggy*» <Ni***@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?


Nov 19 '05 #2

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

Similar topics

0
by: Rhino | last post by:
I am working with SQL Functions in DB2 for Windows/Linux/UNIX (V8.2.1) and am having a problem setting input parameters for SQL Functions to null in the Development Center. My simple function,...
2
by: Chris | last post by:
Hi, I'm new to ASP.Net and Crystal but I've been playing with some samples and have run into a problem. If I put all my code into the Page_Init sub of a single form and run that form, the...
4
by: Patrick Olurotimi Ige | last post by:
I have a DropDown Lsit set to ddlGetDebtor.Items.Insert(0, "-Select Debtor Code-") which is setting the "-Select Debtor Code-" to be default And on PostBack i'm passng:- Cmd.Parameters.Add(New...
3
by: Nobody | last post by:
Hi -- I'm developing an ASP.NET application in VS.NET and I want the startup page to read in some parameters from a querystring. But I can't figure out where to set the querystring. I thought it...
8
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
11
by: Alexander Walker | last post by:
Hello I would like to write a method that allows me to pass a reference to an instance of a class, the name of a property of that class and a value to set that property to, the method would then...
0
by: Greg Pyle | last post by:
I have created a parameter query (qryAuthors) that reads three parameters from three different fields on a subform (Subform1). Each time the form record changes, the query updates automatically. ...
2
by: StuckProgrammer | last post by:
Hi, I have 10 queries linked together via an incident number. There is a form where the user enters start and end dates to define which incident numbers are used within the queries. On running...
5
by: dana1 | last post by:
Hello Experts! Does anyone know if there is a way to set the values of query parameters from VBA for a report's recordsource? (i.e., I want to set the values of the parameters and NOT have the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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,...

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.