如何解决下一个错误:名称“ StoredProcedures”在当前上下文中不存在?

时间:2019-05-17 08:55:10

标签: c#

我需要将存储过程连接到数据库,但是出现错误:

  

名称“ StoredProcedure”在当前上下文中不存在

代码:

private void btnOrdenarCliente_Click(object sender, EventArgs e)
{
    //Realizar la conexion a la Base de Datos
    // Here the error mentioned in the title appears
    SqlConnection cn = new SqlConnection(StoredProcedures.Properties.Settings.Default.MiConexion); 

//这里是错误

    //crear el dataAdapter
    SqlDataAdapter da = new SqlDataAdapter();

    //crear el sqlCommand
    da.SelectCommand = new SqlCommand();

    //pasarle la conexion al Command del DataAdapter
    da.SelectCommand.Connection = cn;

    //indicar el nombre del stored procedure a llamar
    da.SelectCommand.CommandText = "ConsultaClientes";

    //Indicar de que tipo es el command
    da.SelectCommand.CommandType = CommandType.StoredProcedure;

    //añadir un parametro de entrada
    SqlParameter param;
    param = new SqlParameter("@ape ", SqlDbType.VarChar);
    param.Direction = ParameterDirection.Input;
    param.Value = txtApellido.Text;
    da.SelectCommand.Parameters.Add(param);

    //correr el stored procedure
    DataSet ds = new DataSet();
    da.Fill(ds, "Cliente");
    dgvListaClientes.DataSource = ds.Tables[0];
    dgvListaClientes.Refresh();
}

0 个答案:

没有答案