 |
|
ใช้ C# Windows Form อยากรู้วิธีการ AutoNumber โดยไม่ให้เลขซ้ำกันค่ะ
ที่ทำอยู่คือ Import ไฟล์เข้าโปรแกรม แล้วให้รันเลขตามลำดับที่ Import ไป แต่ติดปัญหาคือ มันจะนับลำดับเลขแค่ Import ในตอนนั้นเท่านั้น
เช่น
ครั้งแรก Import ข้อมูล
รหัส | ชื่อ
P001 => Gen ออกมาเอง | A
P002 => Gen ออกมาเอง | B
ครั้งที่สอง
รหัส | ชื่อ
P001 => Gen ออกมาเอง แต่อยากให้เป็น P003 | C
P002 => Gen ออกมาเอง แต่อยากให้เป็น P004 | D
รบกวนผู้รู้ช่วยทีจ้าาา งงมาก
Code ค่ะ
Code (C#)
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
tr = Conn.BeginTransaction();
sb.Remove(0, sb.Length);
sb.Append("INSERT INTO tableSet (AsId,AsName)");
sb.Append("VALUES (@Asid,@AsName)");
string sqlSave = sb.ToString();
cmd.CommandText = sqlSave;
cmd.CommandType = CommandType.Text;
cmd.Connection = Conn;
cmd.Transaction = tr;
cmd.Parameters.Clear();
cmd.Parameters.Add("@Asid", SqlDbType.VarChar).Value = dataGridView1.Rows[i].Cells[0].Value;
cmd.Parameters.Add("@AsName", SqlDbType.VarChar).Value = dataGridView1.Rows[i].Cells[1].Value;
cmd.ExecuteNonQuery();
tr.Commit();
}
MessageBox.Show("เพิ่มข้อมูลเรียบร้อยแล้ว", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
private void button3_Click(object sender, EventArgs e)
{
int cellnum = 0;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
cellnum = cellnum + 1;
dataGridView1.Rows[i].Cells[0].Value = txtID.Text + "000" + cellnum;
}
}
Tag : .NET, Excel (Word.Applcaition), Win (Windows App), C#, VS 2010 (.NET 4.x), Windows
|
ประวัติการแก้ไข 2012-09-18 03:49:50 2012-09-18 21:18:37
|
 |
 |
 |
 |
Date :
2012-09-18 03:36:43 |
By :
porn_toon |
View :
2367 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |