Add new records into SQL db via datagrid

Discussion in 'ASP .Net Datagrid Control' started by James, Oct 1, 2003.

  1. James

    James Guest

    Hello group:

    I've searched through several postings on this question, and either
    they are not quite what I'm looking for, or I'm totally overlooking
    it.

    What I have is a form with 3 text boxes. Users will enter data into
    these boxes, click a button, and the data will be added to a datagrid.
    When the users are finished adding their records, they will then click
    a button to insert the datagrid records into the database.......but,
    how do I do this? Since I didn't fill the datagrid with any existing
    records, I can't really call the update method, can I? Will I have to
    manually iterate through each datagrid / dataset row and call an
    insert procedure for that row, then move to the next? If so, can
    someone show me how to do that?


    Many thanks,

    James
     
    James, Oct 1, 2003
    #1
    1. Advertising

  2. Hello James,

    Thanks for posting in the group.

    For a datagrid, there should be some data source which is bound to it. To
    update the original database with all of these changes, we meed pass the
    DataSet into the Update method of the DataAdapter object.

    However, before you can call Update, you must set the InsertCommand,
    UpdateCommand, and DeleteCommand properties of the DataAdapter object. You
    can manually write SQL and populate these three properties with
    corresponding SqlCommand objects, but you can also use Visual Studio .NET
    to generate these three commands automatically.

    For details, please refer to
    "HOW TO: Update a Database from a DataSet Object by Using Visual C# .NET"
    http://support.microsoft.com/?id=307587

    Does that answer your question?

    Best regards,
    Yanhong Huang
    Microsoft Online Partner Support

    Get Secure! - www.microsoft.com/security
    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    !From: (James)
    !Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    !Subject: Add new records into SQL db via datagrid
    !Date: 1 Oct 2003 13:56:26 -0700
    !Organization: http://groups.google.com
    !Lines: 20
    !Message-ID: <>
    !NNTP-Posting-Host: 192.44.136.113
    !Content-Type: text/plain; charset=ISO-8859-1
    !Content-Transfer-Encoding: 8bit
    !X-Trace: posting.google.com 1065041787 16459 127.0.0.1 (1 Oct 2003
    20:56:27 GMT)
    !X-Complaints-To:
    !NNTP-Posting-Date: Wed, 1 Oct 2003 20:56:27 +0000 (UTC)
    !Path:
    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!newsfeed.cwix.co
    m!news.maxwell.syr.edu!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!postnews1
    .google.com!not-for-mail
    !Xref: cpmsftngxa06.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridcontrol:6857
    !X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    !
    !Hello group:
    !
    !I've searched through several postings on this question, and either
    !they are not quite what I'm looking for, or I'm totally overlooking
    !it.
    !
    !What I have is a form with 3 text boxes. Users will enter data into
    !these boxes, click a button, and the data will be added to a datagrid.
    !When the users are finished adding their records, they will then click
    !a button to insert the datagrid records into the database.......but,
    !how do I do this? Since I didn't fill the datagrid with any existing
    !records, I can't really call the update method, can I? Will I have to
    !manually iterate through each datagrid / dataset row and call an
    !insert procedure for that row, then move to the next? If so, can
    !someone show me how to do that?
    !
    !
    !Many thanks,
    !
    !James
    !
     
    Yan-Hong Huang[MSFT], Oct 2, 2003
    #2
    1. Advertising

  3. I am currently using a dataset, but I'm beginning to think I'm going to
    have to create an object dataset instead of a programmatically created
    dataset.

    On my form with the 3 text boxes, clicking the Add button would add that
    entry into the dataset, then rebind the dataAdapter to the datagrid and
    show the new entry. Then when the user was ready to commit, a 'Save'
    button would be clicked, and the records would be written to the
    database. I had "assumed" that I would not be able to use the update
    method because I was not originally calling any records to update. Would
    I have to at least write a Select query against the datasource that
    never returned any records, then call the update method to write the new
    entries to the database?

    James Lankford
    MCSE


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    James Lankford, Oct 2, 2003
    #3
  4. Hello James,

    Thanks for the response.

    You could follow the steps in that KB artilce to achieve it step by step.
    Calling Update method should be enough to insert the data into database.
    And, InsertCommand, UpdateCommand and DeleteCommand properties should be
    set.

    Please post here if there are any questions.

    Best regards,
    Yanhong Huang
    Microsoft Online Partner Support

    Get Secure! - www.microsoft.com/security
    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    !From: James Lankford <>
    !References: <>
    !X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
    !Subject: RE: Add new records into SQL db via datagrid
    !Mime-Version: 1.0
    !Content-Type: text/plain; charset="us-ascii"
    !Content-Transfer-Encoding: 7bit
    !Message-ID: <>
    !Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    !Date: Thu, 02 Oct 2003 07:35:17 -0700
    !NNTP-Posting-Host: actionjackson133.dsl.frii.net 216.17.147.133
    !Lines: 1
    !Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    !Xref: cpmsftngxa06.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridcontrol:6870
    !X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    !
    !I am currently using a dataset, but I'm beginning to think I'm going to
    !have to create an object dataset instead of a programmatically created
    !dataset.
    !
    !On my form with the 3 text boxes, clicking the Add button would add that
    !entry into the dataset, then rebind the dataAdapter to the datagrid and
    !show the new entry. Then when the user was ready to commit, a 'Save'
    !button would be clicked, and the records would be written to the
    !database. I had "assumed" that I would not be able to use the update
    !method because I was not originally calling any records to update. Would
    !I have to at least write a Select query against the datasource that
    !never returned any records, then call the update method to write the new
    !entries to the database?
    !
    !James Lankford
    !MCSE
    !
    !
    !*** Sent via Developersdex http://www.developersdex.com ***
    !Don't just participate in USENET...get rewarded for it!
    !
     
    Yan-Hong Huang[MSFT], Oct 3, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U0s=?=
    Replies:
    4
    Views:
    1,274
    =?Utf-8?B?c2s=?=
    Dec 10, 2003
  2. Michael
    Replies:
    2
    Views:
    9,062
    magscy
    Jul 19, 2009
  3. Luke Airig
    Replies:
    0
    Views:
    796
    Luke Airig
    Dec 31, 2003
  4. Replies:
    0
    Views:
    323
  5. Belinda
    Replies:
    4
    Views:
    366
    Bob Barrows [MVP]
    Jun 11, 2004
Loading...

Share This Page