0
public partial class Main_Activity : System.Web.UI.Page
{
    private string constr = ConfigurationManager.AppSettings.Get("constr");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["cid"] != null) { loadData(Convert.ToString(Request.QueryString["cid"])); }
        else { loadData("all"); }
    }

    private void loadData(string catId)
    {
        phContents.Controls.Clear();
        DataTable DT = new DataTable();
        OdbcCommand cmd;
        OdbcConnection conn = new OdbcConnection(constr);
        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
            OdbcCommand sql = new OdbcCommand("SET CHARACTER SET `tis620`", conn);
            sql.ExecuteNonQuery();
            sql.Dispose();
        }

I can't run this page. It said "The ConnectionString property has not been initialized" at conn.open()
can anyone help me please.I'm totally new to asp.net so any comment apreciated.

Edited by __avd: Added [code] tags

5
Contributors
5
Replies
9
Views
5 Years
Discussion Span
Last Post by JorgeM
0

You need to save the connection strings under <connectionString/> section and read it using System.Configuration.ConfigurationManager.ConnectionString["CnStr_Name"].ConnectionString.

<connectionStrings>
     <add name="CnStr" 
          connectionString="............" 
          providerName="System.Data.SqlClient"/>
</connectionStrings>
0

Hi please am a new member here, i came across this site while i was looking for help. Am working on a new web site on visula studio c sharp and i have one text field to select a data from the database. Please how do i connect the text field to database and how do i write the selection command.

0

Firstly you start a new thread (button at the top of the page) so you're not hijacking someone else's, its considered impolite. Then we help you:)

0

To clarify since Aviplo indicated he was new to asp.net, the connection string section that adatapost was referring to is located in the web.config file.

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.