日期:2014-05-18  浏览次数:20717 次

初始化字符串格式不符合规范
web.config文件配置:
XML code

 <appSettings>

    <add key="FCKeditor:BasePath" value="~/fckeditor/"/>

    <add key="FCKeditor:UserFilesPath" value="/Files/" />
    

  </appSettings>

  <connectionStrings>
    <add name="decoraconn"  connectionString="server=localhost;uid=sa;pwd=251209;database=decorations" providerName="System.Data.SqlClient"/>
  </connectionStrings>


按钮代码:
C# code

protected void btnLogin_Click(object sender, EventArgs e)
    {
        string connstring =System.Configuration.ConfigurationManager.ConnectionStrings["decoraconn"].ConnectionString;
        SqlConnection con = new SqlConnection("connstring");
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType=CommandType.Text;
        cmd.CommandText ="select * from Admin where account="+tbName.Text;
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            if (dr["password"].ToString() == tbPwd.Text)
            {
                Response.Redirect("index.aspx");
            }
            else {
                lblMessge.Visible = true;
                lblMessge.Text = "登陆失败,密码错误!";
            }
        }
        else {
            lblMessge.Visible = true;
            lblMessge.Text = "登陆失败,用户不存在!";
        }
        dr.Close();
    }



运行的时候提示:从索引 0 处开始,初始化字符串的格式不符合规范。是怎么一回事呀,设置不对么

------解决方案--------------------
SqlConnection con = new SqlConnection("connstring") 改为
 SqlConnection con = new SqlConnection(connstring);

去掉双引号