Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three table in SQL server express that are customers, problem, sub problems what I want to do is be able to edit them from a single ASP page by choosing from a ddl that has 3 choices (customers, problem, sub problem) and that choice of the ddl then displays a gridview of the data in the selected table with option to update or delete the rows.
I can create a ddl which selects the tables from the SQL database sys.tables, but I need to use the selected name as a variable to display the contents of the table in a grid view. so if I select customers from the ddl the customers table is displayed and I can edit it, if I select problem then problem is displayed etc.etc. - any ideas gratefully appreciated, cheers Kevin.

SQL code:
SQL
select T.name collate database_default as TableName
from Incident_Tracker.sys.tables as T where Name like 'Customers' or Name like 'problemType' or Name like 'problemsubType' or name like 'Products'or name like 'Sub_Products'


ASP Code to select ddl:
VB
Protected Sub Page_Load4(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
       If Not IsPostBack Then
           ddlSelectTable.AppendDataBoundItems = True
           Dim strQuery As [String] = "select T.name collate database_default as TableName from Incident_Tracker.sys.tables as T where Name like 'Customers' or Name like 'problemType' or Name like 'problemsubType' or name like 'Products'or name like 'Sub_Products'"
           sqlCon = New SqlConnection(strConn)
           Using (sqlCon)
               Dim sqlComm As New SqlCommand()
               sqlComm.CommandType = CommandType.Text
               sqlComm.CommandText = strQuery
               sqlComm.Connection = sqlCon
               Try
                   sqlCon.Open()
                   ddlSelectTable.DataSource = sqlComm.ExecuteReader()
                   ddlSelectTable.DataTextField = "TableName"
                   ddlSelectTable.DataValueField = "TableName"
                   ddlSelectTable.DataBind()
               Catch ex As Exception
                   Throw ex
               Finally
                   sqlCon.Close()
                   sqlCon.Dispose()
               End Try
           End Using
       End If
   End Sub



Added code for page with grid view - the issue is I cant pass the variable from the ddl selection into the select statement for the grid view, then get the grid view to auto generate the columns from the results of the select statement. then I want to be able to edit or delete rows in the grid view as required.
Below code for aspx page.

HTML
<pre lang="HTML"><pre lang="HTML"><pre lang="HTML">
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="managecustomers.aspx.vb" Inherits="WebApplication4.managecustomers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">

<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<contenttemplate>
<asp:DropDownList ID="ddlSelectTable" runat="server" >





<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Customer_ID" DataSourceID="SqlDataSource1">
<columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="Customer_ID" HeaderText="Customer_ID" ReadOnly="True" SortExpression="Customer_ID" />
<asp:BoundField DataField="Customer_Name" HeaderText="Customer_Name" SortExpression="Customer_Name" />
<asp:BoundField DataField="Customer_AccountNo" HeaderText="Customer_AccountNo" SortExpression="Customer_AccountNo" />





<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Incident_TrackerConnectionString %>" DeleteCommand="DELETE FROM [@TableName] WHERE [Customer_ID] = @Customer_ID" SelectCommand="SELECT * FROM [@TableName]" UpdateCommand="UPDATE [@TableName] SET [Customer_Name] = @Customer_Name, [Customer_AccountNo] = @Customer_AccountNo WHERE [Customer_ID] = @Customer_ID">
<deleteparameters>
<asp:Parameter Name="Customer_ID" Type="Object" />

<updateparameters>
<asp:Parameter Name="Customer_Name" Type="String" />
<asp:Parameter Name="Customer_AccountNo" Type="String" />
<asp:Parameter Name="Customer_ID" Type="Object" />






Thanks.
Posted
Updated 1-May-15 11:12am
v4
Comments
Herman<T>.Instance 1-May-15 8:30am    
What is the problem? the DropDownList or the editing of the table?
Kevin Kinsella 6-May-15 6:00am    
Hi the problem is the passing of the variable produced by the dropdown list into the select, update and delete statements that create the gridview table. any help greatly appreciated thanks.
Herman<T>.Instance 7-May-15 15:08pm    
.SelectedValue ?
Kevin Kinsella 6-May-15 6:00am    
Hi the problem is the passing of the variable produced by the dropdown list into the select, update and delete statements that create the gridview table. any help greatly appreciated thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900