I have a problem wanting to call a stored procedure in c #, the stored procedure is to look for a name of a client, I already try it with the select which works for me but wanting to use a stored procedure does not work for me someone could help me
It works for me this way, I'm using a textbox which when I put the client's name shows it to me in the datagridView, but wanting to do it with the stored procedure does not work for me
public DataTable Buscar(string descripcion)
{
connectionSql.Open();
SqlCommand cmd = new SqlCommand(string.Format("SELECT * FROM CATALOGO WHERE NAMECLIENTE LIKE '%{0}%'",descripcion), connectionSql);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
ds = new DataSet();
ad.Fill(ds,"@NAME");
connectionSql.Close();
return ds.Tables["@NAME"];
}
I did it this way but it marks me an error
public DataTable Buscar(string descripcion)
{
SqlCommand cmd = new SqlCommand("CALL SP_BUSCAR", connectionSql);
cmd.CommandType = CommandType.StoredProcedure;
connectionSql.Open();
SqlDataAdapter ad = new SqlDataAdapter(cmd);
ds = new DataSet();
ad.Fill(ds,"TABLA");//AQUI LO CAMBIE POR @NAME PERO NO FUNCIONA
//QUE ES EL WHERE DEL STORED PROCEDURE
connectionSql.Close();
return ds.Tables["TABLA"];
}
DataTable dtresultado = new DataTable();
try
{
SqlCommand sqlcmd = new SqlCommand("CALL SP_BUSCAR",connectionSql);
sqlcmd.CommandType = CommandType.StoredProcedure;
connectionSql.Open();
SqlDataAdapter sqlDat = new SqlDataAdapter(sqlcmd);
sqlDat.Fill(dtresultado);
sqlcmd.ExecuteNonQuery();
connectionSql.Close();
}
catch (Exception ex)
{
dtresultado = null;
}
return dtresultado;