Updating DataBase with DataTable & TableAdapte problem in C#?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Updating DataBase with DataTable & TableAdapte problem in C#?

  1. #1
    Join Date
    Jun 2008
    Posts
    57

    Updating DataBase with DataTable & TableAdapte problem in C#?

    Hi all.
    I've had a DataBase that named Database1.mdf
    After that VS2008 SP1 creates a DataSet in my Project, named Database1DataSet
    Then I've created a TableAdapter.
    Now I wanna update the DataBase with them ( DataSet & DataTable & TableAdapter ).
    I used this code :

    Code:
    Database1DataSetTableAdapters.eventsTableTableAdapter eventsTableTableAdapte =
        new WpfApplication1.Database1DataSetTableAdapters.eventsTableTableAdapter();
    Database1DataSet.eventsTableDataTable eventsTableDataTable = 
        new Database1DataSet.eventsTableDataTable();
    eventsTableTableAdapte.Fill(eventsTableDataTable);
    
    var id = (from c in eventsTableDataTable.Distinct()
              select c.id).Last();
    id++;
      
    DataRow newDataRow = eventsTableDataTable.NewRow();
    newDataRow["event"] = "event" + id.ToString();
    newDataRow["date"] = id;
    eventsTableDataTable.Rows.Add(newDataRow);
    eventsTableTableAdapte.Update(eventsTableDataTable);
    
    eventsTableTableAdapte.Dispose();
    eventsTableDataTable.Dispose();

    But the changes not apply to the DataBase , Why ? Confused
    What's wrong with it ?

    Many thanks in advance.

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Updating DataBase with DataTable & TableAdapte problem in C#?

    And is there an exception? Also, you are not creating and setting the connection, so some connection based on connection string used in design time is used. Are you sure it is right? Maybe other database is updated than the one you would expect to be.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  3. #3
    Join Date
    Jun 2008
    Posts
    57

    Re: Updating DataBase with DataTable & TableAdapte problem in C#?

    is there an exception?
    No, there isn't
    Also, you are not creating and setting the connection,
    As I know if VS2008 creates it, otherwise an exception has occurred .
    Maybe other database is updated than the one you would expect to be.
    I don't think so, because I've used the DataTable of DataBase1

  4. #4
    Join Date
    Jun 2008
    Posts
    57

    Re: Updating DataBase with DataTable & TableAdapte problem in C#?

    No one cann't help me ?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center