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
- 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:
- 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;
- }