jeudi 14 janvier 2021

filling a table in sql with c# - the fill is just stopping every time it reaches to a random number

filling a table in SQL with c# - the fill is just stopping every time it reaches to a random number. it seems like in a random Iteration the random that changes the value of val2 just decides that he doesn't want to change himself.

public static void GenerateLicenseTable()
{
    string[] array = new string[3];
    Random rnd = new Random();
    string tableName = "license_per_state";
    string colsNames = "state_id" + "," + "license_id" + "," + "from_age";
    string values;

    for (int i = 1; i <= 50; i++)
    {
        //array = new string[3];
        Array.Clear(array, 0, array.Length - 1);

        for (int j = 0; j < 3; j++)
        {
            string val1 = i.ToString();
            string val2 = rnd.Next(1, 7).ToString();
            array[j] = val2;

            for(int k = 0; k < j; k++)
            {
                if(array[k] == val2)
                {
                    val2 = rnd.Next(1, 7).ToString();
                }
            }

            string val3 = rnd.Next(16, 22).ToString();
            values = val1 + "," + val2 + "," + val3;
            RanDAL.Instance.NaiveInsertInto(tableName, colsNames, values);
        }
    }
}



Aucun commentaire:

Enregistrer un commentaire