Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 496
  • Last Modified:

C# .NET2 Windows DB App


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?

  • 2
  • 2
2 Solutions
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:

Gautham JanardhanCommented:
psimationAuthor Commented:
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?
Gautham JanardhanCommented:
i think that will be the most basic :-(
u can go thru that and i will explain all the bits u find difficult ..
psimationAuthor Commented:
Sorry for the delay, hadn't had time to actually go through this.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now