101 Samples for Visual Studio 2005

Hi,

I wonder if anybody can maybe help me.

I recently downloaded the "101 Samples for Visual Studio 2005", from the following link http://lab.msdn.microsoft.com/vs2005/downloads/101samples/default.aspx

I wanted to test and see how Datasets work in the new SQL Express.

The application that I was testing is called "Reading and Writing Images from a Database", and is located in the Data Access folder.

When I run the application, I can select a new picture and assign it to a group. When I click the INSERT button, the dataset is updated and the code that attempts to save the details. It uses the command <dataset>.AcceptChanges().
I have stepped through the code and no errors are generated when this command is executed.

I then go into the Database and take a look and there isn't anything saved or any new entries created.

I have tried the other Data Access applications that insert data into the database,  but they too dont insert anything into the Db's.

I have re-install .NET and SQL Express but the same thing still happens.

Does anyone know how I can go about resolving this issue

Please help!


Answer this question

101 Samples for Visual Studio 2005

  • Flippy_TK

    Hi dkocur2,

    I have attached some sample code below. I see it does the update on the TableAdapter object like you mentioned previously but when I check the database, their still isn't any new records


    private void insertData_Click(object sender, EventArgs e)

    {

    // Create an instance of the new StopWatch class to mark the performance

    // of changing the batch sizes.

    Stopwatch myWatch = new Stopwatch();

    // disable the button and change the text

    insertDataButton.Text = "Processing...";

    insertDataButton.Enabled = false;

    ClearControls();

    // Here you set the batch size of the DataAdapter and the records will

    // be update according this property.

    myDataAdapter.UpdateBatchSize = Convert.ToInt32(batchSizeComboBox.SelectedItem);

    // We start the timer here so we can record only the time required to insert into

    // the DataSet and database.

    myWatch.Start();

    int myNumberofRows = 0;

    // Create new rows for the DataSet

    try

    {

    myNumberofRows = Convert.ToInt32(dataSetSizeComboBox.SelectedItem.ToString());

    for (int i = 0; i < myNumberofRows; i++)

    {

    // For each record inserted, we have to create a new row

    DataRow newRow = myDataTable.NewRow();

    // Give it some value

    newRow["ID"] = i;

    newRow["value1"] = i * 10;

    // Add the new row to the DataSet

    myDataSet.Tables[0].Rows.Add(newRow);

    }

    // After all the new rows have been added to the DataSet, we can update the database.

    // Since we are inserting, all the rows that have been added, will be updated.

    myDataAdapter.Update(myDataSet,"SampleData");

    // We want to explicitly show that the changes have been accepted to update the database

    myDataSet.AcceptChanges();

    Application.DoEvents();

    }

    // If an exception is thrown, we want to reject any changes that were made

    // and display a message

    catch (SqlException ex)

    {

    myDataSet.RejectChanges();

    MessageBox.Show(ex.Message, "Alert");

    }

    // Now we want to stop the timer and display the results

    myWatch.Stop();

    // Display the results in milliseconds

    elapsedTimeLabel.Text = myWatch.ElapsedMilliseconds.ToString() + " ms";

    // Display the rows inserted

    rowsInsertedLabel.Text = "Rows Inserted: " + myNumberofRows.ToString();

    // Display how the data was updated in the WebBrowser control

    finalResultWebBrowser.DocumentText = myStringBuilder.ToString();

    // Display the results in the DataGridView

    FillDataGridView();

    // enable the button and set text back

    insertDataButton.Enabled = true;

    insertDataButton.Text = "Insert Data";

    }// end method


     



    Is there perhaps something wrong with SQL Express 2005 that doesn't commit the data to the database when the TableAdapter.Update(DataSet) is run


  • Ice2Fire

    Tryrone,

    Does SQL Express 2005 have something like the SQL Profiler in SQL 2000 If so, check and see what commands (if any) are actually being sent back to the server.

    Also, in looking at your code above, I assume that myDataAdapter has been defined elsewhere ... are you sure that it's been set up correctly

    Another possibility:
    I notice that you are creating a new DataRow for myDataTable, then when adding to the DataSet you use myDataSet.Tables[0], and finally in your update you're using Update(myDataSet,"SampleData"). Are these all the same table

  • chinkai

    BonnieB,

    I don't think the version of SQL Express that comes with VS 2005.net beta 2 has all the other uitilities as SQL 2000. I think the version that is shipped is similar to the MSDE.

    Yes, the myDataSet.Tables[0] and the table name that is being referenced in the (update) are the same table, as there is only 1 table in the DB.

    The application should run fine as I downloaded it from microsoft http://lab.msdn.microsoft.com/vs2005/downloads/101samples/default.aspx.

    Its the sample applications showing the new features in the VS 2005. The sample I posted previously comes from the (Performing Batch Updates and Data Paging) sample that is installed from the above download.

    All I can think is that there has to be something wrong with the SQL Express installation, although, I have installed and re-installed it and .NET 3 times and I have left all the settings on default for SQL Express.

  • dickdunbar

    DBDataAdapter.Update( DataSet)

  • ssmorgan

    It's been a while since I looked into DataSets, but I don't think AcceptChanges saves the data to the database.  Think of the DataSet as a copy of some of your database data.  This copy behaves like it's own database.  AcceptChanges performs a "commit" to the local copy.  It does not synchronize your copy with the original database.



  • Kenshin1591

    Hi dkocur2

    Thank you for the reply,

    Do you maybe then know of a way that I can get the data to be saved into the Database, or synchronized to the Database

  • 101 Samples for Visual Studio 2005