Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change return of function from string to generic list ?

Status
Not open for further replies.

ahmedsa2018

Programmer
Joined
Apr 25, 2018
Messages
67
Location
EG
problem

How to change return of function from string to return generic list by using csharp ?

I have stored procedure name getcompanies return list of companies id as following

SQL:
create proc getcompannies
as
select compnyid from companes where compnyid > 10


so that result will be as following
11
12
13
14
15
etc...
so that i need to change function below from string to return generic list to be dynamically using

What I have tried:

Code:
public static string ExecuteProcedureReturnString(string connString, string procName,
           params SqlParameter[] paramters)
       {
           string result = "";
           using (var sqlConnection = new SqlConnection(connString))
           {
               using (var command = sqlConnection.CreateCommand())
               {
                   command.CommandType = System.Data.CommandType.StoredProcedure;
                   command.CommandText = procName;
                   if (paramters != null)
                   {
                       command.Parameters.AddRange(paramters);
                   }
                   sqlConnection.Open();
                   var ret = command.ExecuteScalar();
                   if (ret != null)
                       result = Convert.ToString(ret);
               }
           }
           return result;
       }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top