Welcome Guest.   Make a donation to an author on the site October 22, 2014, 07:39:03 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2011! Download 30+ custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Help with databases in Visual Studio C#  (Read 3336 times)
mediaguycouk
Supporting Member
**
Posts: 244


see users location on a map View Profile WWW Give some DonationCredits to this forum member
« on: March 27, 2008, 07:20:09 AM »

Hi everyone,
You might know that I'm trying to learn C# and have started on the small application that I'd write for work.

I've created a form that creates a int Staffnumber, string[] itemreference, datetime ReturnDate.

I also have a database that has key ID, number Staffnumber, text itemreference, datetime ReturnDate, amongst other things.

Visual studio seems to make it very easy to throw my dataset onto the form, but I need to do take my variables and place them into the dataset.

I don't really want someone to write my code for me, but I'm also finding it very hard to find examples and explanations on the internet. I'm hoping that someone who has learnt this before could let me know where they went.

MSDN seems to show me how to do addrow's and things but I can't seem to make inteletext give the options. I think I'm missing something obvious.
Logged

Learning C# - Graham Robinson
giddy
Member
**
Posts: 20


see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #1 on: April 02, 2008, 08:23:25 AM »

hi

I know exactly what you're talking about, I had a large project to do over a year ago and I had to learn ADO.NET and it was so painful because there is hardly much out there about ado.net. You might want to think about getting a book btw, David Sceppa's programming ADO.NET core reference is pretty good.

ok, a DataSet an in memory representation of your tables or schema,  a dataset contains Tables, so when you have the table you want, you do exactly what you mentioned.
(ds = dataset)
DataTable dt = ds.Tables[0];
DataRow row = dt.NewRow()
Now you can do what you want with 'row'

Remember to persist the changes with
ds.AcceptChanges() //if i'm not mistaken!?

Yes, i didn't forget, You probably don't see the NewRow() on intellisense because 1. You don't have using System.Data on the top, and/or 2. You don't have System.Data.dll referenced.

I Hope that was helpful smiley
Gideon
Logged
CWuestefeld
Supporting Member
**
Posts: 939



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #2 on: April 02, 2008, 10:17:32 AM »

I've created a form that creates a int Staffnumber, string[] itemreference, datetime ReturnDate.
...
I also have a database that has key ID, number Staffnumber, text itemreference, datetime ReturnDate

You seem to have a mismatch between the two representations of itemreference. On the form you're showing it as an array of strings, while the table contains a single text column. Was the array a mis-typing, or do you need to rethink the model a bit?

Also, a word to the wise: the TEXT datatype is deprecated in SQL Server. You should be using VARCHAR(MAX) or NVARCHAR(MAX) instead, as TEXT will be removed in a future version.
Logged



mediaguycouk
Supporting Member
**
Posts: 244


see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #3 on: April 02, 2008, 12:39:51 PM »

Hi. After I didn't get any reply here I popped along to the MSDN forum where I got some help

http://forums.microsoft.c...stID=3086413&SiteID=1

At the moment I'm not using MSSQL. I could use it but I'm bouncing between computer and am finding access easier. Hopefully the dataset will allow me to move between them more easily.

Quote
Was the array a mis-typing, or do you need to rethink the model a bit?
It's a booking system. Student ID, Date to return and bookS. So there is a for loop to write each into the database.
Logged

Learning C# - Graham Robinson
wraith808
Supporting Member
**
Posts: 6,417



"In my dreams, I always do it right."

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #4 on: April 02, 2008, 12:54:17 PM »

Sorry Sad  I didn't even notice your post or I would have responded.  Glad you got the help you needed, though!
Logged

CWuestefeld
Supporting Member
**
Posts: 939



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #5 on: April 02, 2008, 02:00:11 PM »

Quote
Was the array a mis-typing, or do you need to rethink the model a bit?
It's a booking system. Student ID, Date to return and bookS. So there is a for loop to write each into the database.
If I understand, then, I think you've got your data model wrong. It sound to me like the itemreference should be a child table with a foreign key pointing back to this table. Then your UI would change from being a big entry field to possibly a listbox.
Logged



mediaguycouk
Supporting Member
**
Posts: 244


see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #6 on: April 02, 2008, 02:20:51 PM »

If I understand, then, I think you've got your data model wrong. It sound to me like the itemreference should be a child table with a foreign key pointing back to this table. Then your UI would change from being a big entry field to possibly a listbox.
I have absolutely no idea what you just said.
Logged

Learning C# - Graham Robinson
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.03s | Server load: 0.04 ]