我生成数字 8,9,A,B (Int64)
但是我需要
00000008
00000009
0000000A
0000000B
000001ED
此代码:
int count = 1;
sb = new StringBuilder();
sb.Append("SELECT max(Numb) FROM tblAs");
string sql = sb.ToString();
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
cmd.Connection = Conn;
count = (int)cmd.ExecuteScalar();
int newCount = count;
int i;
for (i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows.Count > 0)
{
newCount = newCount + 1;
Int64 numTag;
string cTag = Convert.ToString(newCount);
numTag = Int64.Parse(cTag);
cTag = numTag.ToString("X");
if (cTag.Length < 8)
{
int countchar = 8 - cTag.Length;
for (i = 1; i <= countchar; i++)
{
cTag = "0" + cTag;
dataGridView1.Rows[i].Cells[3].Value = cTag;
}
}
}
错误行: dataGridView1.Rows[i].Cells[3].Value = cTag; 消息:索引超出范围。必须是非负数且小于集合的大小。参数名称:索引
谢谢你的时间:)