2013-07-06 44 views
-2

我已經編寫了下面的代碼來生成一些安全代碼,但是這些代碼在訪問中並沒有正確保存,並且所有記錄都是相同的。儘管我追蹤了我的代碼,代碼genrated但這些不同勢碼犯規保存access.just第一代碼保存corectly和其他記錄保存像第一個記錄關於Access數據庫的記錄在我的代碼中都是一樣的

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

正確的值更新「有在代碼中沒有問題「 - 那麼爲什麼在這裏發佈呢? – Hogan

+0

@Hogan爲什麼你玩的話?我的意思是當我跟蹤它時,我看到不同的代碼,但這些代碼在調試Access數據庫 –

+0

時沒有正確保存,參數的值在每次迭代中是否更改,或者是否保留相同? – MEYWD

回答

0

檢查命令與在每次迭代

+1

哦謝謝我真的很無聊,謝謝 –

相關問題