Click here to Skip to main content
15,886,791 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Dear All,


C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class DataReaderFromSql : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataReaderFromSqlAccess();
    }

    public void DataReaderFromSqlAccess()
    {
        string strSql = "Select * from Emp_Details";
        try
        {
            using (SqlConnection cnn = new SqlConnection(
              Common.GetConnectionString("SqlConnectionString")))
            {
                using (SqlCommand cmd = new SqlCommand(strSql, cnn))
                {
                    cnn.Open();
                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                       
                        while (dr.Read())
                        {
                            
                            AccessList.Items.Add(String.Format("{0} {1}",
                              dr["empid"], dr["password"]));
                        }
                    }
                }
            }

        }
        catch (Exception ex)
        {
            errorLabel.Text = ex.Message;
        }
    }


}


How to resolve this error: i got error near the Common, does not exists in current contest
Posted
Updated 9-Apr-12 20:24pm
v2
Comments
Lakamraju Raghuram 10-Apr-12 2:25am    
Rather saying,'near' pin point the error and give more details about the error
Rahul Rajat Singh 10-Apr-12 2:26am    
not clear. what is the error?

You have not included the namespace to the class that includes Common.
Right click on Common and see if you get a resolve option. Use that.

If you don't get it, mostly likely you need to add a reference to the dll.
 
Share this answer
 
Comments
Espen Harlinn 11-Apr-12 11:25am    
5'ed!
Abhinav S 11-Apr-12 12:13pm    
Thank you Espen.
Which error you got near Common?

Better use ConfigurationManager to get Connection String and store your connection String into Web.Config file in connectionString tag
 
Share this answer
 
Comments
2011999 10-Apr-12 2:38am    
i got error in Common
Angel1320 10-Apr-12 8:33am    
Yes you got Error but i want to know what was the error you got?
Hi ,
BY THE WAY Common is class and maybe it doesn't exist :)
your problem in connection string try to use it like this.
XML
<connectionStrings>
    <add name="testConnectionString" connectionString="Data Source=.;Initial Catalog=test;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

Code Behind
C#
protected void Page_Load(object sender, EventArgs e)
{
    DataReaderFromSqlAccess();
}

public void DataReaderFromSqlAccess()
{
    string strSql = "Select * from Emp_Details";
    try
    {
        using (SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString)
           )
        {
            using (SqlCommand cmd = new SqlCommand(strSql, cnn))
            {
                cnn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {

                    while (dr.Read())
                    {

                       xxx =(String.Format("{0} {1}",
                          dr["empid"], dr["password"]));
                    }
                }
            }
        }
     
    }
    catch (Exception ex)
    {
      //  errorLabel.Text = ex.Message;
    }
}


Best Regards
M.Mitwalli
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900