Access数据库中的记录在我的代码中都是相同的

时间:2013-07-06 14:31:12

标签: c# ms-access

我已经编写了以下代码来生成一些安全代码,但是这些代码在访问时没有正确保存,并且所有记录都是相同的。尽管我跟踪了我的代码,每次生成不同的代码但是这些不同的代码不会保存在访问中.just第一个代码保存corectly和其他记录保存像第一个记录

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  ";
}   

1 个答案:

答案 0 :(得分:0)

检查每次迭代时是否使用正确的值更新命令