请帮助我在 c# 上的新人刚刚阅读它脚本上有错误它没有生成下一个数字错误在这一行上显示“使用分配的局部变量 max”
"maxCommand.Parameters.Add("@acn", SqlDbType.VarChar).Value = max.ToString();"
完整编码
private void contact_edit_Click(object sender, EventArgs e)
{
int max;
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\fuda\\Fuda.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
con.Open();
SqlCommand maxCommand = new SqlCommand();
maxCommand = con.CreateCommand();
maxCommand.CommandText = ("SELECT max(acn) from contacts");
maxCommand.Parameters.Add("@acn", SqlDbType.VarChar).Value = max.ToString();
maxCommand.ExecuteNonQuery();
max = max ++;
acn.Text = max.ToString();
}
怎么安排???
example acn = 2253 \\ in table "contact" coulmn acn (A/c number)
if acn = 2253 \\collected max number from acn
acn + 1 \\ add 1 to acn
acn = 2254 \\this should be generate