| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 734 人关注过本帖
标题:ConnectionString 属性尚未初始化
取消只看楼主 加入收藏
肖亭
Rank: 1
来 自:湖北黄冈
等 级:新手上路
帖 子:11
专家分:0
注 册:2013-4-7
结帖率:100%
收藏
 问题点数:0 回复次数:0 
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
快速回复:ConnectionString 属性尚未初始化
数据加载中...
 
   



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

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