Reputation: 7243
I have a sql query that I want to use to get results from a database. When I try to open a sqlconnection, my code won't compile and I get an error asking if i am missing a using directive.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
namespace HackOffice.Superadmin
{
public partial class FoundUsBreakdown : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
grabData();
}
private void grabData()
{
string chartDataQuery = "select AccountType, COUNT(*) Entries from HackOffice.dbo.OnlineSignups group by AccountType";
using (sqlconnection connection = new sqlconnection(connectionString));
}
}
}
I'm confused because I have all the same using directives on other pages and I am not getting the same error on those pages.
Upvotes: 0
Views: 58
Reputation: 149518
Class names are case sensitive in C#. You need SqlConnection
, not sqlconnection
.
Also, you're creating an empty using
statement which will dispose the resource immediately. When you open a using block, you'll want to put all the code that uses the IDisposable
resource inside the block:
using (SqlConnection connection = new SqlConnection(connectionString))
{
// Code that uses SqlConnection goes inside the block.
}
Upvotes: 1