日期:2014-05-17  浏览次数:20471 次

做一个例子时候,数据库链接connectionstring 链接字符串写不好了...
C# code
    protected void Button1_Click(object sender, EventArgs e)
    {
        string dalei = dalei1.Text.Trim();
        SqlConnection conn = new SqlConnection();
       
        conn.ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True";

        conn.Open();
        SqlCommand comm = new SqlCommand("insert into bigsort(bigsort) values('"+dalei+"')",conn);
        comm.ExecuteNonQuery();
        Label2.Text = "ok";

    }


提示说conn.Connectionstring 处错误,请帮忙看看?哪里错了

我是做个字段,保存到数据库。数据库是设成本地的了。

------解决方案--------------------
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
using(SqlConnection conn = new SqlConnection(""))
{}
------解决方案--------------------
string dalei = dalei1.Text.Trim();
SqlConnection conn = new SqlConnection();

conn.ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True";

conn.Open();
SqlCommand comm = new SqlCommand("insert into bigsort(bigsort) values('"+dalei+"')",conn);
comm.ExecuteNonQuery();
Label2.Text = "ok";




string connectionString="Data Source=127.0.0.1;Initial Catalog=kaka;Persist Security Info=True;User ID=sa;Password=123"

数据库链接符







------解决方案--------------------
再不行加我QQ:728888165