文本框中的C#Last DataGridView行值

时间:2013-03-17 10:00:15

标签: c# datagridview textbox

我有一个DataGridView(绑定到SQL数据库表),列名为“order_ID”。我想要的是在GridView / SQL表中的该列中添加最后填充的值以显示在文本框中。我该怎么做呢?任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

这是你想要达到的目标吗?

int lastRow = yourDataGridView.Rows.Count - 1;
object last_order_ID = yourDataGridView.Rows[lastRow].Cells["order_ID"].Value;
yourTextBox.Text = Convert.ToString(last_order_ID);

希望它对你有所帮助。

答案 1 :(得分:0)

下一个身份:

int lastRow = dataGridView1.Rows.Count-1;
        int last_order_ID = Convert.ToInt32(dataGridView1.Rows[lastRow].Cells["s_id"].Value) + 1;
        txt_num.Text = Convert.ToString(last_order_ID);
相关问题