473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Best approach... Reposting...

I have a form that should come up blank (no data in the text boxes,
etc...). I want the user to be able to fill in the contols on the form
and then save the data to a SQL Server database. My plan up to this
point is to use a dataset and have it bound to the controls in the
form. I want to do this so I can take advantage of Undoing changes
easily. The problem is I don't know how to deal with the dataset when
an initial record hasn't been retrieved to populate the controls (to
allow the user to fill in the controls for a new record). Do I create a
dataset that witn no records in it when the form loads? If so, how
would you do this? Or, do nothing initially, let the user fill in stuff
and when they click on my Save button, this will call the add new
record method? I don't know - I'm confused. I hope I'm making sense
here. Please advise - Thanks!

(Sorry for the re-posts for anyone that has already seen this message,
but I have posted this before late at night, and it seems like by the
time everyone gets to looking at things the next day, it has been
pushed way down on the list and thus nobody has responded)

Nov 17 '05 #1
4 1178
Use the data-adapter wizard to create an adapter with the correct statements
to select, delete, update and insert data to the table you're interested in.

Use the select command to get all or some subset of the data into a dataset
using the fill command. You don't even need to use a real select, just
something to populate the dataset with the columns required.

When you're ready to post the data, Add a new row to the dataset, populate
the columns and call Update on the dataset to insert the new row.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"AMeador" <am******@tampabay.rr.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I have a form that should come up blank (no data in the text boxes,
etc...). I want the user to be able to fill in the contols on the form
and then save the data to a SQL Server database. My plan up to this
point is to use a dataset and have it bound to the controls in the
form. I want to do this so I can take advantage of Undoing changes
easily. The problem is I don't know how to deal with the dataset when
an initial record hasn't been retrieved to populate the controls (to
allow the user to fill in the controls for a new record). Do I create a
dataset that witn no records in it when the form loads? If so, how
would you do this? Or, do nothing initially, let the user fill in stuff
and when they click on my Save button, this will call the add new
record method? I don't know - I'm confused. I hope I'm making sense
here. Please advise - Thanks!

(Sorry for the re-posts for anyone that has already seen this message,
but I have posted this before late at night, and it seems like by the
time everyone gets to looking at things the next day, it has been
pushed way down on the list and thus nobody has responded)

Nov 17 '05 #2
The form I'm working with will have a persons data (name, address,
etc...) with a datagrid that lists events for that person
(appointments, visits, referals, etc...). I want the form fields to be
blank when the form comes up. If the user clicks the Find button,
another form will come up that will let them pick a person from a list
(that will include the presons name and ID number). Once they pick the
person they want, the main form will be filled with the data for that
person (using a dataset). However, if the user is entering a new
person, they should just enter the data in the fields on the form. When
they are done, they will have to click Save to store the data.
I understand that the dataset will keep track of the original values
and the current values for data in a given row. I want to give the user
the ability to scrap their changes and re-populate the data fields with
the original values in the dataset. I was thinking of binding the
dataset columns to the approprite form fields. However this is
confusing me in a few ways. Can I even do this? Can I bind the
datarows, current value to the form fields? If I can, how would I push
the original values into the form fields if the user clicks on Reset to
Origianl button? Would I just have to manually do this, or change some
property, or can I just not do it like this? The other problem is that
when the form first comes up, there is no data in a dataset, as no
Person has been selected yet. This is what was confusing me about the
issue of binding on a blank form. Since there is no data being pulled
into the dataset, how can the values being entered be dealt with in
regards to the dataset? If I understand you right, are you saying just
don't try to do binding at all?
When I do have a dataset, it will be based off of a select that
should only return one row, the Person that they did a search for.
Would I just manually add the row's individual column values to each
form field manually? I guess I could watch the controls focus events
and see if the datarow has changed and if it has, re-enable the Reset
button. I don't know - I have read enough about the datasets and such
that I get basically what they do, I'm just having a hard time seeing
how to apply them to the form fields - especially if they start out
blank.
Again, I appreciate your response and time on this issue - I know
its not an easy topic for short newgroup postings.

--- Andrew

Nov 17 '05 #3
The blank dataset will have all the column mappings set up. If you don't do
a fill command then there will be no data in the dataset. The grid will show
an empty row and you can fill out the information and call the data
adapter's update command.

I did a quick test of this on one of my DB's and entered a couple of new
records just fine.

#1 drag a table onto your form. This will create the adapter and the
connection.
#2 create a dataset for this table
#3 bind it to the datagrid by setting the dataset as the datasource.
#4 add a button that calls the data adapter update command.

IF you are editing a row create a select statement to get the row otherwise
just don't call the dataadapter fill command at-all.

Given the second case, if you run the form the grid will be blank but
populated with the column headings for your fields, add some data and press
the button. You will have a new row in the database.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"AMeador" <am******@tampabay.rr.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
The form I'm working with will have a persons data (name, address,
etc...) with a datagrid that lists events for that person
(appointments, visits, referals, etc...). I want the form fields to be
blank when the form comes up. If the user clicks the Find button,
another form will come up that will let them pick a person from a list
(that will include the presons name and ID number). Once they pick the
person they want, the main form will be filled with the data for that
person (using a dataset). However, if the user is entering a new
person, they should just enter the data in the fields on the form. When
they are done, they will have to click Save to store the data.
I understand that the dataset will keep track of the original values
and the current values for data in a given row. I want to give the user
the ability to scrap their changes and re-populate the data fields with
the original values in the dataset. I was thinking of binding the
dataset columns to the approprite form fields. However this is
confusing me in a few ways. Can I even do this? Can I bind the
datarows, current value to the form fields? If I can, how would I push
the original values into the form fields if the user clicks on Reset to
Origianl button? Would I just have to manually do this, or change some
property, or can I just not do it like this? The other problem is that
when the form first comes up, there is no data in a dataset, as no
Person has been selected yet. This is what was confusing me about the
issue of binding on a blank form. Since there is no data being pulled
into the dataset, how can the values being entered be dealt with in
regards to the dataset? If I understand you right, are you saying just
don't try to do binding at all?
When I do have a dataset, it will be based off of a select that
should only return one row, the Person that they did a search for.
Would I just manually add the row's individual column values to each
form field manually? I guess I could watch the controls focus events
and see if the datarow has changed and if it has, re-enable the Reset
button. I don't know - I have read enough about the datasets and such
that I get basically what they do, I'm just having a hard time seeing
how to apply them to the form fields - especially if they start out
blank.
Again, I appreciate your response and time on this issue - I know
its not an easy topic for short newgroup postings.

--- Andrew

Nov 17 '05 #4
Thanks Bob, I appreciate your time and help. I will try doing this.
Again, thanks!

--- Andrew

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Paul | last post by:
Hi. Just trying to find out the best approach as I beleive it might give me problems later on down the road. I have an ASP.NET application which references a shared database class which...
24
by: wm2004 | last post by:
Which is the best C++ Compiler? Get An Online Business and Make Money! Learn the secrets of many ordinary people who quit their day jobs to pursue an online business. There are many affiliate...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
1
by: Andy Britcliffe | last post by:
Hi I'm faced with the situation where I could have a single physical file that could contain multiplie XML documents e.g file.txt contains the following: <?xml version="1.0"...
1
by: milesm | last post by:
I've spent the last 3 hours reading various MSDN articles, other site articles and news group postings and was wondering what the best approach to my situation would be since I'm unable to come up...
4
by: Ned Balzer | last post by:
Hi all, I am pretty new to asp.net; I've done lots of classic asp, but am just beginning to get my mind wrapped around .net. What I'd like to do is include some code that tests if a user is...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
17
by: 2005 | last post by:
Hi In C++, are the following considered best practices or not? - passing aguments to functions (ie functions do not take any arguments ) - returning values using return statement Anything...
5
by: gw7rib | last post by:
I'm writing a program which has "notes" - these can appear on the screen as windows with text in. It is possible to create an "index note" - at present, this will contain a list of the titles (or...
5
by: =?Utf-8?B?d2VyRA==?= | last post by:
Hello, Im wondering, what's the best method to allow multpiple users to update an xml file at once. In my case, generally no user should be editing the same piece of data at any given time...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.