| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 737 人关注过本帖
标题:ConnectionString 属性尚未初始化
只看楼主 加入收藏
肖亭
Rank: 1
来 自:湖北黄冈
等 级:新手上路
帖 子:11
专家分:0
注 册:2013-4-7
结帖率:100%
收藏
 问题点数:0 回复次数:3 
ConnectionString 属性尚未初始化
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class Default2 : System.Web.UI.Page
{
    protected bool fangfa(string k)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["con"]);
       con.Open();
        string sqlsel = "select count(*) from tb_User where Name='" + k + "'";
        SqlCommand com = new SqlCommand(sqlsel, con);
        if (Convert.ToInt32(com.ExecuteScalar()) > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text != "")
        {
            if (fangfa(TextBox1.Text))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('用户名已存在')</script>");
            }
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('可以注册')</script>");
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('用户名不能为空')</script>");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string A = TextBox1.Text;
        string B = TextBox2.Text;
        string C = TextBox3.Text;
        string D = TextBox4.Text;
        string E = TextBox5.Text;
        string F = TextBox6.Text;
        if (!fangfa(TextBox1.Text))
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["con"]);
            con.Open();
            string sql = "insert into tb_User values('" + A + "','" + B + "','" + C + "','" + D + "','" + E + "','" + F + "','" + DateTime.Now.ToString() + "')";
            SqlCommand com = new SqlCommand(sql, con);
            if (Convert.ToInt32(com.ExecuteScalar()) > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('注册成功')</script>");
                fangfa2(A, B, F);
                TextBox1.Text = TextBox2.Text = TextBox1.Text = TextBox3.Text = TextBox4.Text = TextBox5.Text = TextBox6.Text = "";
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "false", "<script>alert('注册失败')</script>");
            }
            con.Open();
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('用户名已存在')</script>");
        }

    }
    protected bool fangfa2(string A, string B,string F)
    {
      
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["con"]);
        con.Open();
        string sqls = "select count(*) from tb_User where Name='" + A + "'and Pass='" + B + "'and Email='"+F+"'";
        SqlCommand com = new SqlCommand(sqls, con);
        if (Convert.ToInt32(com.ExecuteScalar()) > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
   
}
搜索更多相关主题的帖子: public count where 
2013-10-24 09:33
qq645485165
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:76
专家分:197
注 册:2013-3-16
收藏
得分:0 
你的con和你的webconfiger里一样吗?
2013-11-12 16:52
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:0 
很多朋友都或许遇到过"ConnectionString属性尚未初始化"的提示,根本原因是没有能读到key的值。这时需要校正下配置文件中"con",即确认配置文件路径、名称、密码等输入是否正确

 


出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2014-01-03 09:02
hafoking
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-2-8
收藏
得分:0 
回复 3楼 wangnannan
正解
2014-02-10 08:17
快速回复:ConnectionString 属性尚未初始化
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037927 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved