|
-
Oct 16th, 2006, 04:58 AM
#1
Thread Starter
Hyperactive Member
updating data
Hi
I am new to VB.Net so apologies for not knowing the basics!!
I have created a basic VB application (using Visual Studio .Net 2003) which has a listbox - which is attached to a dataset (which is attached 2 my SQL Server 2000 table), and a textbox.
The user has to select a heading from the listbox and enter a bonus in the textbox, and when clicking on the button it should save the input (which should be simple, right?)
My understanding is I create an insert command for the dataset that is attached to the bonus table with parameters with the user values, then fill the dataset, then update the dataset which will update the database... I have got my logic right?!
THANK U!
-
Oct 16th, 2006, 08:08 AM
#2
Fanatic Member
Re: updating data
Your logic is right...but dont rely on the inbuilt CommandBuilder. You better code your own Commands which you execute on the database. You will find many reference in this forum.
Search for ADO.Net FAQs, ADO.Net basics.
Gd luck
-
Oct 16th, 2006, 08:32 AM
#3
Re: updating data
I'd suggest that you read the ADO.NET tutorial in my signature written by fellow member TechGnome.
-
Oct 17th, 2006, 08:59 AM
#4
Thread Starter
Hyperactive Member
Re: updating data
Thanks for the useful links!
I have been able to populate the listbox (i did it first using the data items in the toolbox, which wrote the code for me) But now i have re-done it using the reference from your link.
However, I am stuck and confused! Basically, where should I be creating the connection variables?! I created in a Sub Main (because unlike the example in the link reference I want the listbox to be populated as soon as the app is run...), which works fine BUT when I use the variables in another sub I get an error saying the variable is undefined... MEANING i am creating private variables (????) for only the Main sub (even though it is shared?!)
Also, when I add, for example a label, the system creates a WithEvents thing... I'm confused... I would have thought I could create all these variables outside any sub, and then use them as global variables....
I'm not sure how I have got so confused?! I thought what I was doing was quite simple...... (prop is, ive just confused myself)
Any help would be greatly appreciated
-
Oct 17th, 2006, 05:47 PM
#5
Re: updating data
All variables have a scope limited to the smallest block in which they're declared. That means that if you declare a variable within an If block then it only exists within that If block. If you declare a variable within a method then it only exists within that method. If you declare a variable within a class then it only exists within that class, although you can make it Public so it's accessible from outside the class. If you declare a variable within your Main method then that variable only exists within that Main method. The fact that the method is declared Shared only means that the method itself is accessible from anywhere, not that any variables declared inside it are accessible. All variables declared within a method are called "local" variables because they exist locally, only within that method.
When you add a control to a form the IDE simply declares a corresponding variable at the class level for you. You can also add data connections and the like to your form in the designer if you want to, or you can declare them yourself in code. If you declare them in code yourself and you want them to be accessible throughout the class in which they're declared then the must be declared at the class level, i.e. outside any method definitions. Having said that, there's no reason that you cannot declare your connections, etc. locally in a method each time you need them. The best choice really depends on the situation and also your own personal preference. No way is wrong, although some may be better than others in certain circumstances.
-
Oct 18th, 2006, 04:11 AM
#6
Thread Starter
Hyperactive Member
Re: updating data
THANK YOU FOR SPENDING TIME TO REPLY!
i get what you saying, and hopefully think im getting somewhere.... my page has three listboxes, 1 = heading1, 2 = heading2, 3=heading3....
( eg Heading1 - Heading2-Heading3 - products
Clothing - T-shirt - Lady - ProductID)
These headings are 3 columns in the same table, (which has not been normalised well)... should I have a seperate DataAdapter for each heading with query:
(eg) SELECT heading1 from table1
and then have three dataset, 1 for each heading?!... is this correct?!
OR can I use 1 DataAdapter to get the three columns:
SELECT heading1, heading2, heading3 from table1
but... how do I get Listbox 1 to ignore repeat headings (because its a hierarchical list) ?!
thanks again!
Last edited by pame1la; Oct 18th, 2006 at 09:01 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|