C# 如何修复向过程添加值的错误?
我得到一个错误: 无法将类型C# 如何修复向过程添加值的错误?,c#,stored-procedures,C#,Stored Procedures,我得到一个错误: 无法将类型string隐式转换为int 这是我的密码: private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { String Id = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); try { using (SqlConn
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());
试试这个:
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));
}
}
请发布SP的代码。错误消息会告诉您问题所在。您能解决问题吗?