Stored procedures and in-line parameters

13/07/2003 - 13:28 por Steve Cook | Informe spam
Hello,

I'm trying to execute a SqlCommand using an SQL string that includes the
name of the stored proc and two input parameters -- but I'm not getting
any records returned, even though when I run the stored proc in query
analyzer or from server explorer in vs.net, I do get a record. Here's my
code:

public SqlDataReader RunSP(string proc, ref string errMsg)
{
try
{
SqlConnection cnn = new SqlConnection(_connectString);
cnn.Open();
SqlCommand cmd = new SqlCommand(proc, cnn);
return cmd.ExecuteReader();
}
catch (Exception e)
{
errMsg = e.Message;
return null;
}
}

Here's the value of the proc string:
Document_Load 48, 'X233X2983JIOKSJB'

I know this should be returning records, but it's not. Does anything
jump out as being wrong? Oh, and here's the connect string I'm using, in
case I have a wrong parameter or something:

Data Source=mycomputername;Initial Catalog=DatabaseName;User
Id=steve;Password=password;

Thanks in advance if anyone can shed some light. In case you're
wondering, I'm not using parameter objects because I want this to be a
generic method that I can call from different objects, just passing in
the SQL string.

Steve

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Preguntas similare

Leer las respuestas

#1 Fatima
14/07/2003 - 16:14 | Informe spam
public SqlDataReader VerAlojamiento (int id)

{

// Create Instance of Connection and Command Object

SqlConnection miConexion = new
SqlConnection(ConfigurationSettings.AppSettings["CadenaConexion"]);

SqlCommand miComando = new SqlCommand("spVerAlojamiento", miConexion);

// Mark the Command as a SPROC

miComando.CommandType = CommandType.StoredProcedure;

// Añade los parámetros al SP

SqlParameter parametroIdAloj = new SqlParameter("@IdAloj", SqlDbType.Int,
4);

parametroIdAloj.Value = id;

miComando.Parameters.Add(parametroIdAloj);

// Execute the command

miConexion.Open();

SqlDataReader resultado miComando.ExecuteReader(CommandBehavior.CloseConnection);

// Return the datareader result

return resultado;

}
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida