By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,214 Members | 1,971 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,214 IT Pros & Developers. It's quick & easy.

Creating GridViews dynamically

P: 1
Hi All,

I'm brand new to asp.net 2.0, and have a simple task of just creating a quick and dirty data entry form with SQL Server 2005 on the back end. I added a gridview to my form, and I can populate it dynamically by choosing from a dropdown that I populate dynamically from the database sys.tables table.

When I choose a table from my dropdown, poof, the gridview is beautifully loaded with all the columns and rows, and the edit and delete buttons on the left. Now I want to edit a row (and omg, eventually ADD a row). From what I've seen, you need to have an UpdateCommand something like "Update <table> Set field1 = @field1, field2 = @field2, ... Where keyfield1 = @keyfield1 and keyfield2 = @keyfield2..."

I can find all the fields and key fields through SQL, but when I click Edit on the grid and choose Update, I get an error that no Update Command exists. Obviously it doesn't know what these @ fields are, and equally obviously I don't know how to provide them.

I know I'm not doing this the MS way, of creating static sqlDataSources, but I don't want 20 gridviews on my form, one for each table, and have to constantly add new ones and change old ones. Is there a way to create the UpdateCommand dynamically, or am I all wet on this?

This reminds me of the old currency manager and the auto-generated Insert, Update, Select commands. They were great for the simplest uses, but do anything meaningful and they were impossible to use. I had a friend lose 10's of thousands of dollars, and the lawsuit, trying to create a commercial application using the currency manager. Is this the same MS trap?

TIA!
Larry
Jun 6 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.