Build Data-centric Windows Forms Apps. without MS SQL Server or MS Access Databases - Learn how to build Windows Forms Apps. with a MSDE Data Tier and Visual Studio .NET.
The LBTT Spot
"Lifeline is focused on developing and marketing systems designed to assist in the early detection of breast and ovarian cancer."



Build Data-centric Windows Forms Apps. without MS SQL Server or MS Access Databases

View C# Source Code

Article Categories:

.Net Framework
.Net Framework 1.1
ADO.NET
ASP.NET
Assemblies
Asynchronous Methods
C#
Collections
Configuration
Delegates
Events
Pocket PC
Regular Expressions
Smart Devices
SQL Server
Visual C#
Visual Studio .NET
Visual Studio .NET 2003
Windows Forms
XML

C# .Net Fun Menu

View Current Page's ASP.NET Source Code
C# Reference
C# Study Flash Cards
Valuable Links
Contact Us
Site Map
Mike's Portfolio

C# Reference Search:

Full Text Search:

Articles by Author:

Code Examples (zipped):

Build Data-centric Windows Forms Apps. without MS SQL Server or MS Access Databases

Learn how to build Windows Forms Apps. with a MSDE Data Tier and Visual Studio .NET.
Category: Windows Forms, Visual Studio .NET, Posted 5/30/2003, By Mike G.

If you need to build data-centric, transaction-based Windows Forms applications where a significant amount of data is to be manipulated then this is the tutorial for you.

In this tutorial you will learn how to use VS.NET and MSDE 2000 for VS.NET Developers to build a simple Windows Form that consumes data from tables stored in the MSDE 2000 engine without the use of the Microsoft SQL Server or Microsoft Access products.
    Tutorial Steps:
      Setup MSDE 2000 for Developers using VS.NET
    1. Install MSDE 2002 for VS.NET Developers if it's not already installed.
    2. The MSDE 2002 for VS.NET Developers installation creates an SQL Server 2000 instance service called MSSQL$VSDOTNET where VSDOTNET is the name of the instance.
    3. Check to make sure the VSDOTNET instance is started by running sqlmangr.exe. If it's not, start it.
      MSDE Win. Form App SQL Service Manager

    4. Create MSDE tables and populating them with data
    5. Open up VS.NET and create a new Windows Application project called MSDEWinFormApp.
    6. Open up the Server Explorer by going to View menu list.

    7. Creating an MSDE 2000 Database
    8. Expand the Servers node then expand the name of the computer then expand the SQL Servers node then expand the MSDE-installed instance (in the form computer_name\instance_name).
      MSDE Win. Form App Server Explorer
    9. Right-click on the VSDOTNET instance and choose New Database.
    10. Enter MSDEWinFormApp as the database name and choose Windows NT Integrated Security.
    11. Expand the MSDEWinFormApp database node in the Server Explorer then expand the Tables node.
    12. Right-click on the Tables node then choose New Table.
    13. For the first row of the Column Name column enter FirstName and set the Data Type to varchar and the Length to 64.
    14. Do the same for the second row but call the field LastName.
      MSDE Win. Form App. New Table
    15. Press [Ctrl]+[S] to save the table.
    16. Enter tblMyNames for the table name then click on OK.
    17. In the Server Explorer right-click on the tblMyNames table and choose Retrieve Data from Table.
    18. Start entering random names of people you know or have heard of in the grid (I entered Bill Gates, Steve Ballmer and Coby Briant).

    19. Creating a Typed Dataset
    20. From the Project menu choose Add New Item then choose Data Set.
    21. Called the Data Set dsNames.xsd.
    22. Go the Server Explorer the drag-and-drop the tblMyNames table onto the dsNames.xsd design window.
      MSDE Win. Form App. DataSet
    23. Press [Ctrl]+[Shift]+[S] to save all of the project files.

    24. Adding controls to the Windows Form
    25. Open up Form1.cs from the Solution Explorer window.
    26. Drag-and-drop a DataGrid and Button control from the Toolbox window to Form1.cs.
      MSDE Win. Form App. Form1
    27. Set the button's (Button1) Text property to Fill DataGrid with Names.
    28. Right-click on Form1.cs in the Solution Explorer window and choose View Code.
    29. Go to the very top of the code window and enter the following: using System.Data; using System.Data.SqlClient;
    30. Open up the Form1.cs form again from the Solution Explorer window.
    31. Double-click on the button (Button1) to create a Click event handler.
    32. In the code window type in the following code: // replace the underline below with the name f your computer: SqlConnection sqlConn = new SqlConnection("Data Source=____\\VSDOTNET; " + "Integrated Security=SSPI; Initial Catalog=MSDEWinFormApp"); try { SqlDataAdapter sqlAdp = new SqlDataAdapter("SELECT * FROM tblMyNames", sqlConn); dsNames ds = new dsNames(); sqlAdp.Fill(ds, "tblMyNames"); sqlAdp.Dispose(); dataGrid1.DataSource = ds.tblMyNames; } catch (Exception err) { MessageBox.Show(err.Message + "\r\n" + err.StackTrace); } finally { sqlConn.Close(); sqlConn.Dispose(); }

    33. That's it - now its time to test the application:
    34. Press the [F5] key to debug your application.
    35. Click on the button on the form to fill the DataGrid with the data of names.
      MSDE Win. Form App. Start