locked
Database is not updated RRS feed

  • Question

  •  

    I am trying to insert data to a simple table using SQL express

    However , I can see the data saved in the DataSet but not in the actual database.

    If I try to insert the same user again , I got primary key violation ???

     

    Here is the insert function :

    string SqlConnection = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\QJ.mdf;Integrated Security=True;User Instance=True";

    SqlConnection Conn = new SqlConnection(SqlConnection);

    SqlDataAdapter DataAdapter = new SqlDataAdapter("SELECT * FROM USERS", Conn);

    SqlCommandBuilder ComandBuilder = new SqlCommandBuilder(DataAdapter);

    DataAdapter.InsertCommand = ComandBuilder.GetInsertCommand();

    DataAdapter.UpdateCommand = ComandBuilder.GetUpdateCommand();

    DataSet DS = new DataSet();

    DataAdapter.Fill(DS, "USERS");

    DataTable DT = DS.Tables["USERS"];

    DataRow DR = DT.NewRow();

    DR["NAME"] = txtUserName.Text;

    DR["Password"] = txtPass.Text;

    DR["Type"] = 1;

    DT.Rows.Add(DR);

    DataAdapter.Update(DS,"USERS");

    DS.AcceptChanges();

    Conn.Close();

     

     

     

     

     

    I dont know what I have done wrong

    Please help

    Thanks very much

    Tuesday, June 12, 2007 9:18 PM

Answers

All replies

  • This is possibly happening because you are looking in the wrong place for your database to be updated. The DataDirectory variable is a tricky one and could lead to issues. Follow this link to get a clear understanding for where to look for data in SQL Express and see if this solves the problem.

     

    http://blogs.msdn.com/smartclientdata/archive/2005/08/26/456886.aspx

     

    HTH

    Tuesday, June 12, 2007 9:48 PM
  • Thanks very much , However even when I open the database in the bin folder it is still empty ??

    I am using the Copy if newer value

     

    Thanks again

    Tuesday, June 12, 2007 9:58 PM
  • Could you elaborate more on what exactly that you are doing?
    Tuesday, June 12, 2007 10:12 PM
  • I am trying to add data to a table with 3 col , I followed the instructions of how to insert data to the DB using the comandbuilder .

    I can read from the DB , I can write to dataset , I can see that number of rows are increment , however I cant see the change take place in the DB

    you can see my code above

     

    Thanks very much for your help

     

     

     

    Tuesday, June 12, 2007 10:16 PM
  • Sorted , managed to see the new info in the bin directory

    Thanks very much

    Tuesday, June 12, 2007 10:29 PM