Jump to content

Index and length must refer to a location within the string. Parameter name: length

Execute0426
Go to solution Solved by beingGamer,
1 minute ago, Execute0426 said:

i don't understand. sorry :(

suppose "hello" is my string (max index can be 4)

and I try to access character located at index 10

hi guys i have an error with this"Index and length must refer to a location within the string.
Parameter name: length".

 

with this code:

 

  db.Open();
  MySqlCommand SQL1 = new MySqlCommand("INSERT INTO `Billing`.`tblcustomer` (`CustomerID`, `LastName`, `FirstName, `MiddleName`, `Gender`, `Address`, `ContactNo`, `E-mail`, `Payment`, `Plan`, `Status`) VALUES ('" + getCustomerID() + "', '" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox3.Text + "', '" + comboBox1.Text + "', '" + textBox4.Text + "', '" + textBox5.Text + "', '" + textBox6.Text + "', '" + comboBox2.Text + "', '" + comboBox3.Text + "', '1')", db);
 SQL1.ExecuteNonQuery();
 db.Close();
 MessageBox.Show("One data added.", "Validation", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

 

Link to comment
Share on other sites

Link to post
Share on other sites

you are trying to access character within a string using index which doesnt exist in min & max range of that string.

 

share exact line on which you are getting the exception

Desktop:

CPU : i5 4440 | Motherboard : Gigabyte B85M-D3H | RAM : Kingstone HyperX blu 4GB x2 | GPU : Asus R9 280X DC II Top [RIP 2017] | PSU : Corsair VS 550W | Display(s) : Dell S2240L | Mouse : Logitech G400s | Operating System : Windows 7 64bit

 

Laptop:

Acer Predator Helios 300 (CPU: Intel Core i5 7300HQ | GPU: GTX 1050ti | RAM: 16GB RAM | Operating System: Windows 10 64bit)

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Execute0426 said:

i don't understand. sorry :(

suppose "hello" is my string (max index can be 4)

and I try to access character located at index 10

Desktop:

CPU : i5 4440 | Motherboard : Gigabyte B85M-D3H | RAM : Kingstone HyperX blu 4GB x2 | GPU : Asus R9 280X DC II Top [RIP 2017] | PSU : Corsair VS 550W | Display(s) : Dell S2240L | Mouse : Logitech G400s | Operating System : Windows 7 64bit

 

Laptop:

Acer Predator Helios 300 (CPU: Intel Core i5 7300HQ | GPU: GTX 1050ti | RAM: 16GB RAM | Operating System: Windows 10 64bit)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×