用add key 或者 add name那种连接方法比如我有个数据库:168 表:users 字段:name 字段:word 在index.aspx里 用datareader读取 并输出这两个字段希望有:Web.config连接库的部分 和index.aspx 的方法部分 代码 谢谢啦

解决方案 »

  1.   

    是不是你要的 
    <add key="strProvider" value="data source=px14;initial catalog=gxy_new;persist security info=False;user id =sa;workstation id=YJZ;packet size=4096;pwd=123456;"/>
      

  2.   

    是 但是 还需要 读取的实例部分 
    数据库:168 表:users 字段:name 字段:word 在index.aspx里 用datareader读取 并输出这两个字段 
      

  3.   

      <add name="DBConnect" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\168.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /><asp:SqlDataSource ID="SDS" runat="server" ConnectionString="<%$ ConnectionStrings:Database23ConnectionString1 %>" SelectCommand="SELECT [name] ,[word] FROM [user] "></asp:SqlDataSource>
      

  4.   

    <appSettings>
    <add key="HumanResources" value="server=(localhost);Connection Timeout=30;database=HumanTables;uid=;pwd="/>
      </appSettings>
      

  5.   

    key 和 name 的区别是 什么?
      

  6.   

    <appSettings>
    <add key="FJPConnectionString" value="Data Source=192.168.1.1;Initial Catalog=数据库;Persist Security Info=True;User ID=sa;Password=密码"></add>
    </appSettings>
    public bool funOpenCn()
        {
            try {
                SqlConnection adoCn = (SqlConnection)HttpContext.Current.Session["new clsDataBase().funGetConntion()"];
                if (adoCn != null)
                {
                    if (adoCn.State == ConnectionState.Open)
                    {
                        adoCn.Close();
                        
                    }
                    adoCn = null;
                }
                if (adoCn == null)
                {
                    string sConStr = "";
                    sConStr=System.Configuration.ConfigurationManager.AppSettings["FJPConnectionString"].ToString();
                    adoCn = new SqlConnection(sConStr);
                    if (adoCn.State == ConnectionState.Open)
                    {
                        adoCn.Close();
                    }
                    adoCn.Open();
                    HttpContext.Current.Session["new clsDataBase().funGetConntion()"] = adoCn;
                    return true;
                }
                else {
                    return false;
                }
            }
            catch (Exception ex)
            {
                
                new clsBaseNormal().funWriteErrorLog(ex);
                return false;
            }
            
        }
      

  7.   

     
     string cmdstr;
        //数据库连接
        protected SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strProvider"]);
    cmdstr = "SELECT user,name FROM 168 ";
     SqlDataReader reader = u1000.Data_Reader(cmdstr);
                    if (reader.Read() == true)
                    {
                        Session["newmsgsum"] = reader["sum"].ToString();
                        Page.RegisterStartupScript("myscript", "<script>myfun()</script>");
                        reader.Close();
                    }
    public SqlDataReader Data_Reader(string cmdstr)
        {
            try
            {
                if (conn.State.ToString() == "Closed")
                {
                    conn.Open();
                }
                SqlCommand command = new SqlCommand(cmdstr, conn);
                SqlDataReader reader = command.ExecuteReader();
                return reader;
            }
            catch (Exception ex)
            {
                throw new Exception("Data_Reader出错!", ex);
            }
        }
      

  8.   

    是不是 我的问题 没写清楚 主要要的是页面 连接数据库的实例<appSettings>
    <add key="HumanResources" value="server=(localhost);Connection Timeout=30;database=HumanTables;uid=;pwd="/>
      </appSettings>这个web.config有了  那index.aspx读取的实例呢?不创建连接对象么 不打开连接对象么 SQL语句呢 
      

  9.   

    string conString=ConfigurationManager.AppSettings["HumanResources"]); sqlconnection con=new sqlconnection(conString);
    con.open();
      

  10.   

    <add key="ConnString" value="Data Source=(local);Database=its;User id=sa;PWD=sa" /> 
      

  11.   

    web.config:<add key="conn" value="server=(localhost);Connection Timeout=30;database=job168;uid=sa;pwd=i"/>index.aspx:SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["conn"]);
                con.Open;
                string cmdstr = "SELECT * FROM user";
                SqlCommand command = new SqlCommand(cmdstr,con);
                SqlDataReader reader = command.ExecuteReader();
                Response.Write(reader["id"]);为什么说 con.open 有问题??