• Advertisement
Sign in to follow this  

Database Programming in C#

This topic is 4260 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to do some database programming for C#. I've been looking around for some tutorials - but havn't found too much that is useful. Do any of you know of any good ones? Or books?

Share this post


Link to post
Share on other sites
Advertisement
MSDN has some great video tutorials about using C#, especially with Sql Server. See here. I recommend lessons 8 and 9; while SQLS Express is used in these, other database engines are very similar to use in .net framework.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nik02
MSDN has some great video tutorials about using C#, especially with Sql Server. See here. I recommend lessons 8 and 9; while SQLS Express is used in these, other database engines are very similar to use in .net framework.


This looks very promising - thank you.

Share this post


Link to post
Share on other sites
That first post was very useful - but I have a follow up question - I want to create a display for the database so that as I am typing it filters to what I have typed.

For example if I have 5 Names:
Alex
Bob
Matt
Michael
Mike

and I type in a textbox "M"
it would now display:
Matt
Michael
Mike

and if I typed "Mi"
it would display:
Michael
Mike

Any ideas?

Share this post


Link to post
Share on other sites
You should write a query that returns records based on your parameter. In Transact-SQL (the language of SQL Server), you could do something like this:

SELECT * FROM Persons WHERE Name LIKE (@Name + '%');

In that expression, @Name is a parameter that you give to the query from the host program, and LIKE compares it to the records with using a wildcard (%) so as to return records that begin with your Name parameter.

On C# side, you can specify that the parameter takes it's value from a control property, such as your textbox's text.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nik02
You should write a query that returns records based on your parameter. In Transact-SQL (the language of SQL Server), you could do something like this:

SELECT * FROM Persons WHERE Name LIKE (@Name + '%');

In that expression, @Name is a parameter that you give to the query from the host program, and LIKE compares it to the records with using a wildcard (%) so as to return records that begin with your Name parameter.

On C# side, you can specify that the parameter takes it's value from a control property, such as your textbox's text.


Thanks - that worked great!

Share this post


Link to post
Share on other sites
New question regarding this same issue - I got it to filter how I want it filtered, however - it will only display one field (i.e. last name) and not all of the fields into a single string or so.

Does anyone have any ideas?

(when I preview the data in the C# SQL builders and what not - it will display all of the data, but when I run the program, it doesn't.)

Share this post


Link to post
Share on other sites
You can use composite values when selecting data from your database. For example:

SELECT FirstName + ' ' + LastName AS FullName FROM Persons;

And then binding the FullName composite field to your control.

You can't perform updates on a composite statement (as the server wouldn't know which physical field to update if you tried to update FullName), but for displaying purposes it works very well. It is always preferable to perform value compositions in as low a level as possible, and database is usually the lowest practical level.

Microsoft has SQL Server tutorials available also; you can download the full documentation, that includes samples and tutorials, here.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nik02
You can use composite values when selecting data from your database. For example:

SELECT FirstName + ' ' + LastName AS FullName FROM Persons;

And then binding the FullName composite field to your control.

Microsoft has SQL Server tutorials available also; you can download the full documentation, that includes samples and tutorials, here.


If that works - you're a saint! Also thank you for the book link, I will have to check that out.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement