Connecting Tech Pros Worldwide Forums | Help | Site Map

Load data from sql in Array

Member
 
Join Date: Sep 2008
Posts: 72
#1: Nov 20 '08
Hey guys i need help with loading an value from a SQL database record

Its like this i have a database with a table in it and in all those table are records and i know you can load 1 reccord value from a reccord into an array

and i now its it done a litle bit like this

.......Array[0] so that with this bit af code he loads the first record from the database into the array .......

......Array[1] and like this reccord number 2 i know this is posible in C# i just cant get it to work cud somone pleas post the code with how i can load a reccord value into an array with a number behingd it so he know wich record to put in the array

Tnx for your help

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Nov 20 '08

re: Load data from sql in Array


Show us what you tried first.
P.S Also read about a neat trick called data binding. It allows you to achieve all that without breaking any bones.
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#3: Nov 20 '08

re: Load data from sql in Array


I'm not sure what your goal is, it was a bit hard to understand...but we have two articles that might help you in using a database:
Member
 
Join Date: Sep 2008
Posts: 72
#4: Nov 20 '08

re: Load data from sql in Array


Il try to explain it again i have a databse in sql like this for example

Firstname Lastname Age

Jan Jansen 44
0 1 2

now i have 3 records with a number on it in sql starts with 0 so it looks like this record 0 is Firstname and so on

now i whanne load the name Jan into an Array someting like this
Expand|Select|Wrap|Line Numbers
  1. txtFirstname.Text = OfferteArray[0];
  2. txtLastname.Text = OfferteArray[1];
  3. txtAge.Text = OfferteArray[2] 
so i whant that the OfferteArray[0] has loaded the value Jan from my database and strored it in the txtbox txtFirstname.Text

Hope you understand me now Tnx for reply
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#5: Nov 20 '08

re: Load data from sql in Array


That OfferteArray again! I'm out of this thread.
Member
 
Join Date: Sep 2008
Posts: 72
#6: Nov 20 '08

re: Load data from sql in Array


Haha Tnx for your help man
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#7: Nov 20 '08

re: Load data from sql in Array


OK. One last time.

What you are trying to do with those arrays all over the place is very Fortranesque.
Better use object oriented programming these days. Simply create a small class that represents your table structure. You then read data row by row creating objects of that class type with the data and store those objects in ONE ArrayList where you can then manipulate them at your own leisure.

P.S Several useful hints have already been given to you for your problem but you seem to be ignoring them and starting off multiple threads for the same problem.

P.P.S Remember that double posting is not allowed in these forums.

P.P.P.S: this is really the last time!
balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Posts: 757
#8: Nov 20 '08

re: Load data from sql in Array


Quote:

Originally Posted by r035198x

OK. One last time.

What you are trying to do with those arrays all over the place is very Fortranesque.
Better use object oriented programming these days. Simply create a small class that represents your table structure. You then read data row by row creating objects of that class type with the data and store those objects in ONE ArrayList where you can then manipulate them at your own leisure.

P.S Several useful hints have already been given to you for your problem but you seem to be ignoring them and starting off multiple threads for the same problem.

P.P.S Remember that double posting is not allowed in these forums.

P.P.P.S: this is really the last time!

P.P.P.P.S: And he really means it this time...
Member
 
Join Date: Sep 2008
Posts: 72
#9: Nov 24 '08

re: Load data from sql in Array


Just for addition info i am not just reading your posts (i dont ignore your hints)i try to use them in my code if i can but i am not superp in english as i think you see in more of my posts so i somethimes have trouble knowing what evry word means and i am gratful your trying to help me but there were differnt errors on the post i posted before but i whont open a new post ont this bit of code anymore just hope you whanne help me with this new error on the same code

Hey i think i got 1 step farther becase now i get an differnt error and if i leave the txt OfferteArray in the code he will still runn the application but i get an error later on in a method

Dont now if you still whanne try to help but i need to try i cant do it myself XD

the error message i get now is

No overload for method 'GetOfferteGegevens' takes '1' arguments

And yes i first lookd on the internet for solutions but cudent find any useful 1
Weird thing is that the error message is differtn from the code error becase the bleu line is under dbConn

here is the code hope somone is interested enouf to try to help

Expand|Select|Wrap|Line Numbers
  1.         #region Invullen van de tekstvelden uit Database
  2.         public void Vullen_tekstvelden(string[] OfferteArray, bool nieuw)
  3.         {
  4.             localhost1.dbConnection dbConn = new localhost1.dbConnection();
  5.             OfferteArray = dbConn.GetOfferteGegevens(txtNoteID.Text);
  6.             txtNoteID.Text = OfferteArray[0];
  7.             txtBTW.Text = "25";
  8.             txtOfferteNr.Text = OfferteArray[1];
  9.             txtDatum.Text = Functions.DateToNL(OfferteArray[2]);
  10.             txtDebNr.Text = OfferteArray[3];
  11.             txtKlantNaam.Text = OfferteArray[4];
  12.             txtContactpersoon.Text = OfferteArray[5];
  13.             txtOmschrijving.Text = OfferteArray[6];
  14.             txtOrderNr.Text = OfferteArray[7];
error is rule number 5 i think on the dbConn.GetOfferteGegevens lap of code
Reply