Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何修复向过程添加值的错误?_C#_Stored Procedures - Fatal编程技术网

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的代码。错误消息会告诉您问题所在。您能解决问题吗?