C# function return datareader
C#
private IEnumerable<T> GetRows<T>(string sql, Action<SqlParameterCollection> addParameters, Func<IDataRecord, T> copyRow)
{
using (var cn = new SqlConnection("Connection string here"))
using (var cmd = new SqlCommand(sql, cn)
{
cmd.CommandType = CommandType.StoredProcedure;
addParameters(cmd.Parameters);
cn.Open();
using (var rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
yield return copyRow(rdr);
}
rdr.Close();
}
}
}
public IEnumerable<MenuItem> GetChildMenus(string url)
{
return GetRows<MenuItem>("spR_GetChildMenus", p =>
{
//these lines are copied from your question, but they're almost certainly wrong
p.AddWithValue("@PageUrl", url);
p.AddWithValue("@MenuId", ParameterDirection.Output);
p.AddWithValue("@ParentId", ParameterDirection.Output);
p.AddWithValue("@TitleText", ParameterDirection.Output);
p.AddWithValue("@ExternalUrl", ParameterDirection.Output);
p.AddWithValue("@FullUrl", ParameterDirection.Output);
p.AddWithValue("@ChildCount", ParameterDirection.Output);
}, r =>
{
return new MenuItem( ... );
}
}
Also in C#:
- Title
- .net core download image from url binary file
- Category
- C#
- Title
- c# format number with leading zeros
- Category
- C#
- Title
- how to insert into a list c#
- Category
- C#
- Title
- asp net mvc 5 return view from another controller
- Category
- C#
- Title
- unity ui change sprite
- Category
- C#
- Title
- uinput dialog uwp c#
- Category
- C#
- Title
- fahrenheit to celsius c#
- Category
- C#
- Title
- firefoxoptions setpreference to trust certificates
- Category
- C#
- Title
- first sentence letter capital in c#
- Category
- C#
- Title
- unity invoke
- Category
- C#
- Title
- asp list box
- Category
- C#
- Title
- replace all ponctuation characters c#
- Category
- C#
- Title
- block wapalyzer from detecting codeigniter
- Category
- C#
- Title
- c# reverse a string for loop
- Category
- C#
- Title
- how to get odd saturday in a month in c#
- Category
- C#
- Title
- how to destroy a gameobject after some hits in unity 3d
- Category
- C#
- Title
- unity rotation
- Category
- C#
- Title
- webutility.urlencode space
- Category
- C#
- Title
- c# enum default
- Category
- C#
- Title
- c# create dynamic object
- Category
- C#
- Title
- c# making a folder
- Category
- C#
- Title
- set object to random color unity
- Category
- C#
- Title
- c# split a string and return list
- Category
- C#
- Title
- C# graph api upload file one drive
- Category
- C#
- Title
- unity transformer double en float
- Category
- C#
- Title
- linq foreach c#
- Category
- C#
- Title
- make camera follow character unity 2020
- Category
- C#
- Title
- array copy c#
- Category
- C#
- Title
- c# array Reverse method
- Category
- C#
- Title
- c# clear list items
- Category
- C#
- Title
- Net.ServicePointManager.SecurityProtocol .net framework 4
- Category
- C#
- Title
- What is a class in c#
- Category
- C#
- Title
- zoom gedit
- Category
- C#
- Title
- background color with opacity
- Category
- C#
- Title
- : ? conditioanl statement c#
- Category
- C#
- Title
- unity docs player input
- Category
- C#
- Title
- c# console writeline color
- Category
- C#
- Title
- c# mixed multidimensional array
- Category
- C#
- Title
- how to start an if statement in c#
- Category
- C#
- Title
- wpf get name of clicked element
- Category
- C#
- Title
- json serialize object capitalization config
- Category
- C#
- Title
- null coalesce ternary c#
- Category
- C#
- Title
- how to clear console through script unity
- Category
- C#
- Title
- datetitime contrusctor c#
- Category
- C#
- Title
- countdownevent
- Category
- C#
- Title
- sort datatable c#
- Category
- C#
- Title
- f reachable queue in c#
- Category
- C#
- Title
- isdaylightsavingtime in c#
- Category
- C#
- Title
- initialise icollection c#
- Category
- C#
- Title
- onmouseclick unity
- Category
- C#
- Title
- how to make error sound c#
- Category
- C#
- Title
- linq c# or
- Category
- C#
- Title
- No context type was found in the assembly
- Category
- C#
- Title
- unity timer with miliseconds
- Category
- C#
- Title
- c# append array
- Category
- C#
- Title
- .net core check if linux
- Category
- C#
- Title
- how to change text to bold through script unity
- Category
- C#
- Title
- mvc write to console
- Category
- C#
- Title
- C# Into To Tring Debug.Log
- Category
- C#
- Title
- c# get list of all class fields
- Category
- C#
- Title
- C# webclient immitate browser
- Category
- C#
- Title
- what type of variable is true or false in c#
- Category
- C#
- Title
- how to clamp transform.rotation
- Category
- C#
- Title
- unity change text color
- Category
- C#
- Title
- wpf c# select folder path
- Category
- C#
- Title
- unity c# is not equal to
- Category
- C#
- Title
- c# download string url
- Category
- C#
- Title
- leantween id
- Category
- C#
- Title
- C# colours
- Category
- C#
- Title
- unity round
- Category
- C#
- Title
- unity load text resources from subfolder
- Category
- C#
- Title
- f string C#
- Category
- C#
- Title
- asp.net c# set session timeout
- Category
- C#
- Title
- query associative table ef6
- Category
- C#
- Title
- unity up arrow input
- Category
- C#
- Title
- C# how to get public key for InternalsVisibleTo
- Category
- C#
- Title
- c# getter setter
- Category
- C#
- Title
- how to stop player rotating when hit by object
- Category
- C#
- Title
- how to record number of times using application in c#
- Category
- C#
- Title
- c# reverse string
- Category
- C#
- Title
- how to trim path in C#
- Category
- C#
- Title
- Request.ServerVariables["HTTP_X_FORWARDED_FOR"] get only one ipaddress
- Category
- C#
- Title
- parsing string to int without format exception c#
- Category
- C#
- Title
- c# combobox datasource enum
- Category
- C#
- Title
- winforms timer c#
- Category
- C#
- Title
- c# silent execute exe
- Category
- C#
- Title
- as c#
- Category
- C#
- Title
- unity add component
- Category
- C#
- Title
- matplotlib measure the width of text
- Category
- C#
- Title
- letter at index of string c#
- Category
- C#
- Title
- c# lambda expression
- Category
- C#
- Title
- c# reverse array
- Category
- C#
- Title
- convert string to boolean c#
- Category
- C#
- Title
- s3 upload base64 .net core
- Category
- C#
- Title
- how to stop a form c#
- Category
- C#
- Title
- unity custom editor save changes
- Category
- C#
- Title
- how to copy one array value to another without reference c#
- Category
- C#
- Title
- unity load next scene
- Category
- C#
- Title
- unity html request
- Category
- C#
- Title
- unity detect number key
- Category
- C#