Johan Holtby
Johan Holtby

Reputation: 573

How input a list of int pairs to a MySQL store procedure from C#?

How input a list of int pairs to a MySQL store procedure from C#?

I have a list of 2500 int pairs and want to have it as input to be handheld as two columns in MySQL. E.g. I want to send input.

List<IntPair> input = new List<IntPair>();

struct IntPair{
    int a;
    int b;
}

Upvotes: 1

Views: 271

Answers (1)

fubo
fubo

Reputation: 45947

There is no IntPair-Type in MySQL. Use 2 different Int-parameters

using (MySqlConnection myConnection = new MySqlConnection("ConnString"))
{
    myConnection.Open();
    foreach (var item in input)
    {                  
        using (MySqlCommand myCommand = new MySqlCommand("spInputData", myConnection))
        {
            myCommand.CommandType = CommandType.StoredProcedure;
            myCommand.Parameters.Add("@Parameter1", item.a);
            myCommand.Parameters.Add("@Parameter2", item.b);
            myCommand.ExecuteNonQuery();
        }
    }
}

Upvotes: 2

Related Questions