Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

C#: Execute A Query & Return A Reader

DZone's Guide to

C#: Execute A Query & Return A Reader

·
Free Resource

public static SqlDataReader GetReader(string Query)
{
	string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["CONNECTION_STRING_NAME"].ConnectionString;
	SqlConnection con = new SqlConnection(ConnectionString);
	SqlCommand command = new SqlCommand();

	command.Connection = con;
	command.Connection.Open();
	command.CommandText = Query;
	return command.ExecuteReader();
}
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}