我有个表login,就一个int字段,我在vs里,利用新建查询  执行sql语句 insert into login values(2)
能正确插入数据但是我用以下语句操作的时候SqlConnection sqlconnection = null;                  SqlCommand sqlcommand = null;                  sqlconnection = new SqlConnection(" Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database1.mdf;Integrated Security=True;User Instance=True");                  try
                  {
                      sqlconnection.Open();                      MessageBox.Show("连接状态:" + sqlconnection.State, "连接Sql", MessageBoxButtons.OK, MessageBoxIcon.Information);
                  }
                  catch (SqlException ex)
                  {
                      MessageBox.Show("发生错误:" + ex.Message, "连接Sql", MessageBoxButtons.OK, MessageBoxIcon.Error);
                  }                  sqlcommand = new SqlCommand("INSERT INTO login VALUES(999)", sqlconnection);                  int result =  sqlcommand.ExecuteNonQuery();                  sqlconnection.Close();并没有报告错误,但是数据并没有插入数据库,没有任何反应。不知原因。求救

解决方案 »

  1.   

    你的Database1.mdf数据库放哪里的?有那么一种可能,你放在项目中了,导致每次编译都会自动覆盖这个文件一次,你的修改自然就不会生效。
      

  2.   

    是不是要在 INSERT INTO login VALUES(999) 上加上 数据库的 限定 , 看你没有 initial category
      

  3.   


    好似是这种情况,或者你找错数据库了,譬如DEBUG运行去REALSE目录看结果去了
      

  4.   

    连接错误
    在数据库运行试试--------------------------------------------------------------
      C#常用代码集合库 - 功能完整|效率高速|文档丰富 using(DbHelper sql = new SqlHelper()){
                sql.SetConnectionString("(local)\\SqlServer", "userName", "password", "database");            sql.Execute("select * from table");  //执行
                while(sql.Read())
                    Console.Write(sql.DataReader["column"].ToString());        }