0

Hello,
I want to make a connection to MSSQL 2008 database, using Visual Studio 2010, ASP.NET C# web site
I wrote this connection string in web.config file:

<connectionStrings>
    <add name="konekcija"
         connectionString="data source=.\SQLEXPRESS;Initial Catalog=Movies;Integrated Security=True;" providerName="System.Data.SqlClient" />
  </connectionStrings>

Now I need to call that connection on a code behind the page... something like:
SqlConnection conn = new SqlConnection.... can anyone help?
thanks

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by azapovjednik
0
 protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                BindEmployeesList();
            }
        }

        private void BindEmployeesList()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["NorthwindConnString"].ConnectionString;
            string selectSQL = "SELECT [LastName], [FirstName], [Title], [City], [Email] FROM [Employees]";
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand(selectSQL, con);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();

            adapter.Fill(ds, "Employees");

            gvEmployeesList.DataSource = ds;
            gvEmployeesList.DataBind();
        }
0

Thanks Dhaker... I needed C#
I found out what to do... here is the code snippet:

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString());
                SqlCommand cmd = new SqlCommand("SELECT * FROM someTable", conn);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.