我正试图获得最后一排,但问题是....看到我的代码
Int32 index=dataGridveiw1.Rows.Count; // this is count start 1,2,3,4,5,6
sum3=txt_lotweight.Text-txt_balanceweight.Text;
sum4=datagridview1.Rows[index].Cells["rollweight"].Value-sum3;
Run Code Online (Sandbox Code Playgroud)
如何在此代码错误中将gridview的最后一行值减去sum3将导致未找到行索引,因为行计数从1开始,当i减去行值为sum3时,它从0开始
那么如何获得gridview的最后一行
这是我的C#WinForm代码我有2个存储过程,第一个执行Insert in Table1和第二个执行Update Table2都在for循环中.请指导我如何在此代码中使用Commit和Rollback,因为我有GridView和GridView有很多行,如果任何行有不正确的数据,那么没有行插入和更新在表中
try
{
con.Open();
da = DateTime.Now;
if (txt_challanno.Text == "")
{
//MessageBox.Show("Insert Order No.", "Message Box Sample", MessageBoxButtons.OK, MessageBoxIcon.Error);
toolTip1.ToolTipIcon = ToolTipIcon.Warning;
toolTip1.ToolTipTitle = "Warning!";
toolTip1.Show("Missing 'Lot No.'", txt_challanno);
}
else if (txt_challanno.Text != "" && DataGridView1.CurrentRow.Cells["program_no"].Value == null)
{
toolTip1.Hide(txt_challanno);
MessageBox.Show("Insert Program No.");
}
else if (dataGridView1.CurrentRow.Cells["program_no"].Value != null && dataGridView1.CurrentRow.Cells["bundle_weight"].Value == null)
{
toolTip1.Hide(txt_challanno);
MessageBox.Show("Insert Bundle Weight");
}
else if (dataGridView1.CurrentRow.Cells["bundle_weight"].Value == null && dataGridView1.CurrentRow.Cells["pcs"].Value == null)
{
toolTip1.Hide(txt_challanno);
MessageBox.Show("Insert Pcs");
} …Run Code Online (Sandbox Code Playgroud)