ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Help with databases in Visual Studio C#

(1/2) > >>

mediaguycouk:
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.

giddy:
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 :)
Gideon

CWuestefeld:
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
-mediaguycouk (March 27, 2008, 07:20 AM)
--- End quote ---

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.

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

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=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.

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

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

Navigation

[0] Message Index

[#] Next page

Go to full version