C# .NET2 Windows DB App

Posted on 2007-07-23
Last Modified: 2013-11-26

I'm pretty green with .NET and C#, but I have managed to build a couple of "small" web apps in Visual Studio 2005. I've easily managed to create webpages that show a grid view of a db and allows editing/sorting/pagination etc.

Howerver, when I try to build a windows app, I cannot seem to get pagination, edit and delete to work with the DataGridView.

I can get the app to show the table in a grid view, but even though I ticked all the options for pagination, edit/delete and add, it just shows a "read only" version of the table; I can also not seem to specify my own SQL to limit the collumns returned.

When creating a WebApplication, I ran into a similar problem wrt edit/delete - it required that I supply separate update and delte SQL strings and make some other settings in the connectionstring properties, but with the standalone app, I just can't see where to do that.

I'm basically trying to build a very simply app that displays the content of one table, and then to have tick boxes next to each row; all the rows ticked needs to be altered by changing a value in the "count" collumn.

Any pointers/help?

Question by:psimation
    LVL 6

    Accepted Solution

    You didn't mention which data provider you are using, so I assume it is the Microsoft Sql Data Provider.
    If you are population a DataTable with the help of a SqlDataAdapter, add a SqlCommandBuilder object to automatically build the Insert, Update and Delete commands based on the SqlCommand object used to select the data. The use the Update method of the SqlDataAdapter object to save the changes.

    Declare these globally:

                private SqlDataAdapter sqlAdapter;
                private DataTable table;

    This could be done in the Form Load Event to fill the DataGridView:

                SqlConnection sqlConn = new SqlConnection(theConnectionString);
                SqlCommand sqlComm = new SqlCommand(theSelectString, sqlConn);
                sqlAdapter = new SqlDataAdapter(sqlComm);
                SqlCommandBuilder sqlBuilder = new SqlCommandBuilder(sqlAdapter);
                table = new DataTable();

                adapter.Fill(table);    // Also causes the SqlCommandBuilder to create the commands.
                dataGridView1.DataSource = table;

    Update the changes behind a Button Click Event like this:

    LVL 29

    Assisted Solution

    by:Gautham Janardhan
    LVL 17

    Author Comment

    Thx fior the replies so far, I'll have a look during this week and let you know how it goes.

    BTW, quathampj, the link you posted seems interesting, but I'm a total noob with .NET, and the code seems to assume one knows a bit more than my level. Do you have anything a bit more "basic" perhaps?
    LVL 29

    Expert Comment

    by:Gautham Janardhan
    i think that will be the most basic :-(
    u can go thru that and i will explain all the bits u find difficult ..
    LVL 17

    Author Comment

    Sorry for the delay, hadn't had time to actually go through this.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video discusses moving either the default database or any database to a new volume.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now