private void SinhMa() { dtKH = new DataTable(); DataSet ds = blKH.LayDSKHSinhMa(); dtKH = ds.Tables[0]; if (dtKH.Rows.Count == 0) { MaKH_TextBox.Text = "K01"; } else { string a = this.dgvKH.Rows[this.dgvKH.Rows.Count - 2].Cells[0].Value.ToString(); int b = Convert.ToInt32(a.Substring(1)) + 1; if (b < 10) { MaKH_TextBox.Text = "K0" + b.ToString(); } else { MaKH_TextBox.Text = "K" + b.ToString(); } } }