Add new records into SQL db via datagrid

J

James

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
 
Y

Yan-Hong Huang[MSFT]

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: (e-mail address removed) (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: <[email protected]>
!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: (e-mail address removed)
!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
!
 
J

James Lankford

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
 
Y

Yan-Hong Huang[MSFT]

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 <[email protected]>
!References: <[email protected]>
!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: <[email protected]>
!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
!
!
!
!Don't just participate in USENET...get rewarded for it!
!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top