Over a million developers have joined DZone.

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.CommandText = Query;
	return command.ExecuteReader();

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}