我收到错误:
无法隐式将
string
类型转换为int
这是我的代码:
private void dataGridView1_CellValidating(object
sender, DataGridViewCellValidatingEventArgs e)
{
String Id = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
try
{
using (SqlConnection conn = new SqlConnection(_csData))
{
conn.Open();
SqlCommand comm = new SqlCommand("updateTable", conn);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add("@vrID", SqlDbType.VarChar).Value = Id;
SqlDataAdapter da = new SqlDataAdapter(comm);
da.SelectCommand = comm;
DataTable db = new DataTable();
da.Fill(db);
dataGridView1.DataSource = db;
}
}
catch (Exception ex)
{
MessageBox.Show(String.Format("An error occurred: '{0}'", ex.Message));
}
}
我也试过这个:
int Id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());
答案 0 :(得分:0)
试试这个:
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
int Id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());
try
{
using (SqlConnection conn = new SqlConnection(_csData))
{
conn.Open();
SqlCommand comm = new SqlCommand("updateTable", conn);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add("@vrID", SqlDbType.Int).Value = Id;
SqlDataAdapter da = new SqlDataAdapter(comm);
da.SelectCommand = comm;
DataTable db = new DataTable();
da.Fill(db);
dataGridView1.DataSource = db;
}
}
catch (Exception ex)
{
MessageBox.Show(String.Format("An error occurred: '{0}'", ex.Message));
}
}