473,788 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1195
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******@tampa bay.rr.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.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******@tampa bay.rr.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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
1861
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 contains methods for serialising and de-serialising objects to the database storage. I put this as a shared class as multiple web clients will be using the class to store and retreive data, the problem I'm haivng now is that I think multiple threads...
24
2065
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 programs to choose from, but choose an interest you are passionate about and sell it online! Please subscribe to the newsletter below for updates and news:
136
9459
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 code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
1
1743
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" encoding="ISO-8859-1"?> <!DOCTYPE doc SYSTEM "1.0b.dtd"> <doc transmission-date="20050715T154340Z" >
1
1593
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 with the best approach. What's Needed........ 1. Various background SQL inserts that don't interrupt the client request/response 2. Various background emails generated and sent that are separate from the client request/response 3. Every...
4
1841
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 logged in, on each and every page, and redirects the user to a login page if s/he's not logged in. The login page will also take care of some standard setup, such as choosing/populating a user profile. I used to use <!-- #include ... --for this,...
16
2820
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 efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. Two Questions: 1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
17
3049
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 else? The reason for this question is that I had an assignment in which I was
5
1395
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 other data, you can choose) of some or all of the notes - you can choose the selection criteria. Thus you can create notes to store any text you want to, in a relatively free manner, but you can easily fish out all the notes relating to some...
5
3888
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 however there may be ten+ users updating the same xml file at once. The file has grown to somewhere along the lines of 3 MB, but shouldnt get much larger. im afraid that using xmldocument is beginning to become a costly process with such a large...
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.