不存在从对象类型 System.Windows.Forms.DataGridViewTextBoxColumn
if(e.ColumnIndex==1)//点击了修改{stringname=dgvyuangong.Rows[e.RowIndex].Cells["ygname"].V...
if (e.ColumnIndex == 1)//点击了修改
{
string name = dgvyuangong.Rows[e.RowIndex].Cells["ygname"].Value.ToString();
string shenri = dgvyuangong.Rows[e.RowIndex].Cells["ygshenri"].Value.ToString();
string sex = dgvyuangong.Rows[e.RowIndex].Cells["sex"].Value.ToString();
string sfz = dgvyuangong.Rows[e.RowIndex].Cells["ygsfz"].Value.ToString();
int id = Convert.ToInt32(dgvyuangong.Rows[e.RowIndex].Cells["ygID"].Value);
using (cmd = new SqlCommand())
{
cmd.CommandText = "update tbyg set ygName=@name,sex=@sex,ygshenri=@shenri where ygID=@id";
cmd.Connection = con;
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@sex", sex);
cmd.Parameters.AddWithValue("@shenri", ygshenri);
cmd.Parameters.AddWithValue("@sfz", sfz );
cmd.Parameters.AddWithValue("@id", id);
if (con.State.ToString() == "Closed")
{
con.Open();
}
cmd.ExecuteNonQuery();//执行更新 不存在从对象类型 System.Windows.Forms.DataGridViewTextBoxColumn 到已知的托管提供程序本机类型的映射。(就是这里出错了)
MessageBox.Show("修改成功!");
bindBookToDgv();//重新调用绑定并显示
con.Close();
}
} 展开
{
string name = dgvyuangong.Rows[e.RowIndex].Cells["ygname"].Value.ToString();
string shenri = dgvyuangong.Rows[e.RowIndex].Cells["ygshenri"].Value.ToString();
string sex = dgvyuangong.Rows[e.RowIndex].Cells["sex"].Value.ToString();
string sfz = dgvyuangong.Rows[e.RowIndex].Cells["ygsfz"].Value.ToString();
int id = Convert.ToInt32(dgvyuangong.Rows[e.RowIndex].Cells["ygID"].Value);
using (cmd = new SqlCommand())
{
cmd.CommandText = "update tbyg set ygName=@name,sex=@sex,ygshenri=@shenri where ygID=@id";
cmd.Connection = con;
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@sex", sex);
cmd.Parameters.AddWithValue("@shenri", ygshenri);
cmd.Parameters.AddWithValue("@sfz", sfz );
cmd.Parameters.AddWithValue("@id", id);
if (con.State.ToString() == "Closed")
{
con.Open();
}
cmd.ExecuteNonQuery();//执行更新 不存在从对象类型 System.Windows.Forms.DataGridViewTextBoxColumn 到已知的托管提供程序本机类型的映射。(就是这里出错了)
MessageBox.Show("修改成功!");
bindBookToDgv();//重新调用绑定并显示
con.Close();
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询