-2

我编写了以下代码来生成一些安全代码,但这些代码没有正确保存在访问中,所有记录都是相同的。虽然我跟踪了我的代码并且每次生成不同的代码但这些不同的代码没有保存在访问中。只是首先代码正确保存,其他记录像第一条记录一样保存

OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;

cmd.Connection = myconn;

label7.Text = "";
int[] s = new int[15];
int[] a = { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
int[] b = { 0, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
int[] result1 = new int[13];
int[] result2 = new int[13];

int f = Convert.ToInt32(textBox1.Text);

int m = Convert.ToInt32(textBox2.Text);
double sum1 = 0;
double div1 = 0;
double sum2 = 0;
double div2 = 0;
int z = Convert.ToInt32(textBox2.Text) - Convert.ToInt32(textBox1.Text);
if (z >= 400)
{
   Form1 h = new Form1();
   h.Close();
}    

while (f <= m)
{
   int l = f;
   for (int i = 0; i <= 3; i++)
   {
      s[i] = 2;
   }

   s[4] = 0;
   s[5] = 1;

   for (int i = 12; i >= 6; i--)
   {
      s[i] = l % 10;
      l = l / 10;
   }

   for (int i = 0; i <= 12; i++)
   {
      result1[i] = s[i] * a[i];
      result2[i] = s[i] * b[i];
      sum1 += result1[i];
      sum2 += result2[i];
   }

   div1 = sum1 / 11;
   div2 = sum2 / 11;
   double value1 = div1;

   int r = (int)((value1 - (int)value1) * 10);

   double value2 = div2;

   int o = (int)((value2 - (int)value2) * 10);
   if (r == 9)
   {
      s[13] = 0;
   }
   else
   {
      s[13] = r + 1;
   }

   if (o == 9)
   {
      s[14] = 0;
   }
   else
   {
      s[14] = o + 1;
   }

   string we = "";
   for (int q = 0; q <= 14; q++)
   {                  
      we += s[q];
   }

   cmd.Parameters.AddWithValue("@SP", we);
   cmd.CommandText = "INSERT INTO [Counter](SubscriptionCode)" + " VALUES (@SP)";      

   myconn.Open();
   cmd.ExecuteNonQuery();
   myconn.Close();
   f++;
   label7.Text += " \n  ";
}   
4

1 回答 1

0

检查命令是否在每次迭代中更新为正确的值

于 2013-07-06T15:36:17.480 回答