Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  Data Programming  »  ADO.NET  »  ADO.NET for Beginners Part Three  »  Summary
ADO.NET for Beginners Part Three
by David Jeavons | Published  01/12/2007 | ADO.NET | Rating:
David Jeavons
I have been programming database applications for almost 12 years starting out with VB3 and using every major version since then. I currently work for a retailer analysis company writing ASP.NET code for our ever evolving web site. I also enjoy helping other programmers with Visual Basic and .NET and am a moderator at vbCity. 

View all articles by David Jeavons...
Summary

We have now finished converting our existing project to use a Microsoft SQL Server database.    I think you will agree that the difference between the Microsoft Access version and the new version is not that great, especially when you consider that we could have omitted the use of Stored Procedures and continued to use the inline SQL statements. However, the benefit of using Stored Procedures certainly makes this exercise worthwhile; it especially comes in handy when you need to modify some of your queries as you do not need to modify your code, only the Stored Procedures which saves you from having to recompile your programs.

 

So we are now at the end of this series of articles. I certainly hope that it has given you enough information to start working with databases in your programs and to explore other areas and techniques of ADO.NET that will aid you in your database work.

How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent
Tell us why you rated this way (optional):

Article Rating
The average rating is: No-one else has rated this article yet.

Article rating:4.55 out of 5
 20 people have rated this page
Article Score7141
Related Articles
Attachments
Comments    Submit Comment

Comment #1  (Posted by an unknown user on 02/15/2007)
Rating
Thanks alot. It's easy for me a chinese to understand what u talk about.
 
Comment #2  (Posted by Resty on 06/21/2007)
Rating
I'm kinda stuck with this tutorial. I did everything & when I ran the program it would point to the line, "adapter.Fill(dt)" and the error would be: ...that the server might not allow remote connections. The fact is the SQL Server is installed locally. Please advise. Cheers!
 
Comment #3  (Posted by David Jeavons on 06/21/2007)
Rating
Hi Resty

What version of SQL Server are you using?

Also, can you post the connection string you are using.


Thanks
 
Comment #4  (Posted by Resty on 06/22/2007)
Rating
Thanks for your urgent reply. I'm actually using the SQL Server 2005 Express Edition & I'm doing my project in VB 2005 Express Edition. Below is a bit of my code which have the connection string:

Private Sub RetrieveContacts()
Dim conn As New SqlConnection("Data Source=(Local);Initial Catalog=AddressBook;Integrated Security=SSPI")
Dim adapter As New SqlDataAdapter("Contacts_AllContacts_Select", conn)
Dim dt As New DataTable("Contacts")
Try
adapter.Fill(dt)

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

dgContacts.DataSource = dt

End Sub

Hoping for your next reply. Cheers

Resty

 
Comment #5  (Posted by David Jeavons on 06/22/2007)
Rating
Hi Resty

I am not sure that the connection string you are using will work with SQL Server 2005 Express Edition. Instead, you might like to try one of the following:

If you are storing your database in the Data directory then:

Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;

Otherwise, if your database resides somewhere on your machine:

Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;

Hopefully one of these connection strings will resolve your issue.


HTH
 
Comment #6  (Posted by Resty on 06/22/2007)
Rating
Connection now works, but I have another problem. When adding some records & actually saving them, then closing the program & coming back to it again, the data are lost. That also goes with edit & delete function. When program closes, it returns to its original state. What is happening this time?
Please shed light on this. Cheers!


 
Comment #7  (Posted by David Jeavons on 06/22/2007)
Rating
Hi Resty

I think what is happening is that your database file has the property "Copy to Output Directory" set to "Copy Always". This means that each time you build (debug) your application the database file is copied to your output directory and you are then using this database during the lifetime of the application. The next time you run your program this database is overwritten therefore giving the impression that data is not being saved.

You can change this property value to "Do Not Copy" thus ensuring that you are always working with the same database file.


HTH
 
Comment #8  (Posted by Resty on 06/25/2007)
Rating
Thanks David! It's working perfectly now. Looking forward to more articles like this one from you. Really a great tutorial to learn programming!!!
 
Comment #9  (Posted by an unknown user on 07/03/2007)
Rating
Exactly what I was looking for. Most tutorials target design database manipulation techniques instead of programatic techniques.
Fantastic tutorial.
 
Comment #10  (Posted by an unknown user on 10/26/2007)
Rating
Outstanding. Just outstanding for me, a beginner. Outstanding. Thanks much.
 
Comment #11  (Posted by an unknown user on 11/14/2007)
Rating
Straight forward tutorial, exactly what the novice needs.
 
Comment #12  (Posted by an unknown user on 12/27/2007)
Rating
Very good job a explaining how to create a database project for access and SQLServer.
 
Comment #13  (Posted by Steve on 01/14/2008)
Rating
Thank you very much for taking the time and effort to write a superb set of tutorials - I have learned more in the last 3 nights than in the previous 3 months!
Question - in SQL databases, what is the difference between "Do not copy", "Copy if Newer", and "Copy Always".
Again thank you.
Steve
 
Comment #14  (Posted by David Jeavons on 01/15/2008)
Rating
Hi Steve

Thank you for your comments.

To answer your question, the "Do not copy" will ensure that when you compile your application, the database will not be copied to the output (build) directory. The "Copy if Newer" will only copy the file to the output directory if the file is newer. However, be careful with this option as when you compile your application the date of the file may change in which case the file will be copied even if the contents have not changed. Finally the "Copy Always" option will always copy the file to the output directory.

I personally find it safer to use the "Do not copy" option and ensure that I manually copy the database file. Thus ensuring that no changes are overwritten by mistake.


HTH
 
Comment #15  (Posted by an unknown user on 02/14/2008)
Rating
Great article!
 
Comment #16  (Posted by an unknown user on 02/23/2008)
Rating
Super!!!
 
Sponsored Links