MySql Exception by Selecting Auto_Increment Values C#
Posted by: Maximilian Schmidt
Date: March 26, 2016 02:49PM

0
down vote
favorite
I want to get the username and userid, but when i executing the command I get the Exception:

Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: startIndex"
The Database has the Items: UserID(AutoIncrement Int(9)(PK)) and UserName(Varchar(20))

Code:

using (MySqlConnection connection = new MySqlConnection(DBConnection.ConnectionString))
{
connection.Open();
MySqlCommand getUser = new MySqlCommand("SELECT * FROM User Where UserID = '42'", connection);
MySqlDataReader reader = getUser.ExecuteReader();
if (reader.HasRows){
The Exception is thrown at "ExecuteReader".
Queue

"Select* From User Where UserID ='42'" is Executing without any trouble on the Server.

I also tried only the query

SELECT * FROM User Where User
But I get the same exception.

I can insert into the Table and I can get the Last insert ID but when I try to every Database with Select * From XY I get the same Exception. All the Tables are with innobDB and the all have at least 1 primary or foreign key.

If I only select the UserName the Query is working:

Select UserName From User

But when I try to get the UserID

Select UserID From User

I get the Exception:

{"Destination array is not long enough to copy all the items in the collection. Check array index and length."} System.Exception {System.ArgumentException}

Options: ReplyQuote


Subject
Written By
Posted
MySql Exception by Selecting Auto_Increment Values C#
March 26, 2016 02:49PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.