输入字符串的格式不正确。
我使用uniqueidentifier作为我的id在sql server数据库错误显示在ID = ...
private void DataGridViewDischarge_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
ID = Convert.ToInt32(DataGridViewDischarge.Rows[e.RowIndex].Cells[0].Value.ToString());
TxtHeadOverNotch.Text = DataGridViewDischarge.Rows[e.RowIndex].Cells[1].Value.ToString();
TxtDischargeQ.Text = DataGridViewDischarge.Rows[e.RowIndex].Cells[2].Value.ToString();
}
答案 0 :(得分:1)
Unique Identifier GUID , GUID
无法表示为 int
所以您必须将其解析为GUID,请参阅here:
Guid id = Guid.Parse(DataGridViewDischarge.Rows[e.RowIndex].Cells[0].Value.ToString());
答案 1 :(得分:0)
private void dgv_expenditure_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
DataGridViewRow dgv = dgv_expenditure.Rows[e.RowIndex];
int id = Convert.ToInt32(dgv.Cells[0].Value);
tabControl1.SelectedIndex = 1;
loadform(id);
}
private void loadform(int id)
{
// throw new NotImplementedException();
SanmolCAEntities1 _db = new SanmolCAEntities1();
var u = _db.a_expenditure.Where(p => p.id == id).FirstOrDefault();
txt_name.Text = u.name;
txt_CreateBy.Text = u.createby;
dateTimePicker_excrdate.Value.ToString("yyyy-MM-dd HH:mm:ss");
txt_updateBy.Text = u.updateby;
dateTimePicker_exupdate.Value.ToString("yyyy-MM-dd HH:mm:ss");
}
错误在这一行:
int id = Convert.ToInt32(dgv.Cells[0].Value);
这是错误; 输入字符串的格式不正确