I get the above error using this code. What am I missing?
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Data.Common;
public partial class Families_Bartholomew : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnShowEvents_Click(object sender, EventArgs e)
{
string strSQL = "Select * FROM EventsBart";
try
{
using (SqlConnection cnn = new SqlConnection(Common.getConnectionString("EventsDBSqlConnection")))
{
using (SqlCommand cmd = new SqlCommand(strSQL, cnn))
{
cnn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
lbEvents.Items.Add(String.Format(dr["EventName"], dr["EventDate"]));
}
}
}
}
}
catch (Exception ex)
{
ErrorLabel.Text = ex.Message;
}
}
}
I think the problem is in your 27th line, with Common.getConnectionString("EventsDBSqlConnection")).
If you look at the top of your code where you have using System.Data.Common; this is already mentioned, so you don't need to use
Common in the code anymore, but, as I see, getConnectionString might be your custom made method and Common a custom class you use. If thats true, then, if its from other Namespace, add the namespace like
using NamespaceName;
So, take a look around it.
Regards,
Hajan
Best Regards,
Hajan
Dont forget to Mark as Answer the answer that solved your problem!
Common.getConnectionString() is a library function in this case and you are missing the reference.
Check in your project if you have namespace which contains Common class. if its example take from other source and you do not have common class available then you can also do:
using (SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["EventsDBSqlConnection"].ConnectionString))
this is too late!I know, but I used this forum now!
check this out!
try
{
using (SqlConnection cnn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["TestConnectionString1"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand(str, cnn))
{
cnn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
wadebart
Member
6 Points
43 Posts
The name 'Common' does not exist in the current context
May 11, 2010 12:11 PM|LINK
I get the above error using this code. What am I missing?
using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using System.Collections; using System.Configuration; using System.Data.Sql; using System.Data.SqlTypes; using System.Data.Common; public partial class Families_Bartholomew : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnShowEvents_Click(object sender, EventArgs e) { string strSQL = "Select * FROM EventsBart"; try { using (SqlConnection cnn = new SqlConnection(Common.getConnectionString("EventsDBSqlConnection"))) { using (SqlCommand cmd = new SqlCommand(strSQL, cnn)) { cnn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { lbEvents.Items.Add(String.Format(dr["EventName"], dr["EventDate"])); } } } } } catch (Exception ex) { ErrorLabel.Text = ex.Message; } } }adeelehsan
All-Star
18223 Points
2725 Posts
Re: The name 'Common' does not exist in the current context
May 11, 2010 12:37 PM|LINK
Hi
On line 27, you have the following code:
using (SqlConnection cnn = new SqlConnection(Common.getConnectionString("EventsDBSqlConnection")))
What is Common here?
asp .net 2.0
MCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011
hajan
Star
10655 Points
1782 Posts
Re: The name 'Common' does not exist in the current context
May 11, 2010 12:43 PM|LINK
Hi,
I think the problem is in your 27th line, with Common.getConnectionString("EventsDBSqlConnection")).
If you look at the top of your code where you have using System.Data.Common; this is already mentioned, so you don't need to use Common in the code anymore, but, as I see, getConnectionString might be your custom made method and Common a custom class you use. If thats true, then, if its from other Namespace, add the namespace like using NamespaceName;
So, take a look around it.
Regards,
Hajan
Hajan
Dont forget to Mark as Answer the answer that solved your problem!
My ASP.NET Weblog
hajan
Star
10655 Points
1782 Posts
Re: The name 'Common' does not exist in the current context
May 11, 2010 12:44 PM|LINK
You were probably faster.
Sorry, I didn't see your post.
Hajan
Dont forget to Mark as Answer the answer that solved your problem!
My ASP.NET Weblog
SSA
Star
9368 Points
1576 Posts
Re: The name 'Common' does not exist in the current context
May 11, 2010 01:00 PM|LINK
Common.getConnectionString() is a library function in this case and you are missing the reference.
Check in your project if you have namespace which contains Common class. if its example take from other source and you do not have common class available then you can also do:
pankaj_rayal
Member
316 Points
99 Posts
Re: The name 'Common' does not exist in the current context
May 04, 2011 05:51 AM|LINK
That's it..
if you required complete code you can let me know at pankaj_rayal@hotmail.com
mohsenhs82
Member
9 Points
4 Posts
Re: The name 'Common' does not exist in the current context
Dec 11, 2012 11:24 AM|LINK
hi
this is too late!I know, but I used this forum now!
check this out!
try
{
using (SqlConnection cnn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["TestConnectionString1"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand(str, cnn))
{
cnn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{