In a web site the user has to choose one out of several sql tables to deal with.
He will then be allowed to view the selected table data through a GridView, to insert a new row into and to update a row in the selected table by means of an array of TextBoxes created dynamically on the base of the selected table.
I think it is possible to solve the problem fully by properly configuring at run time an SqlDataSource.
I have solved the issue of data display by declaring in the code behind within the OnPageLoad sub the following:
SqlDataSource1.SelectCommand ="Select * FROM " & selectedTable
While for the GridView1 I have added the selected table columns to the columns collection as follows:
for i=0 to ColumnCount-1
Dim cacAs BoundField =New BoundFieldcac.HeaderText = HeaderNamesArray(i)
cac.DataField = ProductNamesArray(i)
Me.GridView1.Columns.Add(cac)next
I have difficulty on how to do similar declarations for the insertcommand and update command.
Update and Insert are a bit more tricky. Essentially you have to build the statement including all of the table fields.
Insert Into(Field1, Field2, etc) Values(Value1, Value2, etc)
You can get the field names from the .Columns collection on a dataset, but you'll also need the datatype for the field, since you'll have to delimit string values with single quotes.
Update involves on additional issue in that you have to know the primary key...
Update Table Set Field1=Value1, etc Where PK=PKValue of row that you are on.
In short you've got your work cut out for yourself, but it can be done.
Good luck.
|||Ciao Alex
I understand that it is too complicated to go the way I thought feasible.
I will have to accept to use a DetailsView control which is not the best graphical solution for my application.
Thanks for your concrete help
federico
No comments:
Post a Comment