Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a sp its return type is int what type i should declare in business logic
how to use execute scalar function there or should i use data table or dataset
Posted

1 solution

Int in SQL is int in c#.

ExecuteScalar() will work fine with less overhead than DataSets.
 
Share this answer
 
Comments
Member 11970398 18-Nov-15 1:25am    
public int ExecuteScalar(String storedprocedure, params SqlParameter[] arrParam)
{
SqlConnection cn = new SqlConnection(connection());
try
{
//initialisation of datatable, Sql connection and sql command
DataSet dt = new DataSet();

SqlCommand cmd = new SqlCommand(storedprocedure, cn);
cmd.CommandType = CommandType.StoredProcedure;

//opens the db connection
if (cn.State == ConnectionState.Closed || cn.State == ConnectionState.Broken)
cn.Open();

//if sql param is not null then gets the parameters from that
if (arrParam != null)
{
foreach (SqlParameter param in arrParam)
cmd.Parameters.Add(param);
}
cmd.CommandTimeout = 5000;
//executes the command and fills it into the datatable

return string;
}

catch (Exception ee)
{

return null;
}
finally
{
cn.Close();
}
}
its showing error on return
it should return 2 thins if success true of false type or 1 ,0
Mehdi Gholam 18-Nov-15 1:30am    
What is the error?
Member 11970398 18-Nov-15 1:33am    
in return line error string invalid expression
Mehdi Gholam 18-Nov-15 1:37am    
Then check you paramaters match the sp's parameters.
Member 11970398 18-Nov-15 1:40am    
can u check this method .is it perfect ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900