.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Dynamically bind to often changing database

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net


Please point me to the right forum if this is not correct - I do appreciate it :-)

At work we have a database that needs a table maintenance utility written in c#/aspx/webforms. The database has about 45 tables and that could change fairly frequently.

The utility needs to present the user with a drop down of all the tables in the database, (ok - easy so far. I can get this dynamically from the database to allow for addition/deletion of tables). The user chooses a table name and is presented with the data in the table. The user can edit the data, delete or insert rows, page through the data, etc. I am guessing this is a gridview.

I can get the columns for the selected table name dynamically from the database too, but I do not seem to be able to write a generic page that uses code to bind the gridview to the data and lets the user page, insert or delete rows, etc.

In the designer a sql datasource on non-changing tables this would be easy. (Point the sds at the table, write a couple of stored procedures to add/delete/select rows, etc and the job is done).

What I don't seem to be able to do is write a generic page that will cope with dynamic binding of the grid to the database. i want to write a page that is fairly 'decoupled' from changes in the database but will still be able to provide a useful table-maintenance type tool.

View Complete Post

More Related Resource Links

how to bind menu dynamically at runtime to database

Hi I'm new to ASP.Net. I need to bind data to menu navigation control from DataBase. These are the Tables I have...I know how to bind data from web.sitemap and xml, but not through database. If any changes are made in database, then automatically it should update in menu navigation control..plz guide me... Services --> E - Learning Education Software Products --> Education Individuals Corporate Customers --> Testimonials Careers --> Work Culture Current Openings About US --> Quality Policy Our Founder Our Team Thanks in Advance... even i can write code for it .but the main problem is that i dont know how i should create table structure .also navigate url column plz help

.NET Reflection: Dynamically Bind Your Data Layer to Stored Procedures and SQL Commands Using .NET M


One major inconvenience of using SQL stored procedures from code is having to match type information. You have to write long wrapper functions around the procedures just to expose the data types. In the .NET Framework, however, the reflection services of the System.Reflection namespace allow you to query rich metadata that describe data types. This article explains how to use reflection in .NET to end your stored procedure nightmares. The author creates four custom classes, including one that generates a SQLCommand object based on the metadata of a method. Using this library, you'll be on your way to automating the generation of stored procedures.

Atif Aziz

MSDN Magazine August 2002

Dynamically Create a Database (LINQ to SQL)

 Hello... I want to create an install script for a simple little CMS I have created for myself... I want to pass the connection string and then create my tables. I found the following example on MSDN: http://msdn.microsoft.com/en-us/library/bb399420.aspx My question is how do I pass the username and password to the DB... or even better if there is an example of this somewhere that would be great.   Thanks!

Database vs XML for complex changing data

Hello, I'm researching and experimenting with aspects of a new project before final design.  It will be in two parts: 1. a designer interface (like visio)2. client to display the content created within the designer interface. We have the design outline in place, the client will be in many forms, via the web using Flash or Silverlight (depending what's installed) and via windows using a WPF application. I would like to know what people think regarding storing information from the designer, all the clients will need to access the information via the internet so a database storage solution seems the first choice. But another alternative is exporting the information from the designer in something such as XML and storing that as a physical file. The designer will be an application allowing the users to create multiple pages (like PowerPoint slides), each of which they have control over placement objects (images, text, buttons etc). A database approach will require a lot of work when changes are made with update, delete and inserts every time a page (slide) is changed. The XML approach seems easier to manage because each time the page (slide) is amended the XML file can either be delete and recreated or the content inside replaced with the new designer layout. It would be great to hear what other people think. I was thinking for XML to separate each slide into a separate


the database result is as follows DATE     code   class1 class2  class3 1/8/10     M1     10       20     30     3/8/10     V2      20       30     10      1/8/10      H1      1           2      3         7/8/10     ! ! 8/8/10     !M2    5      5      5       3/8/10     B2      4      4     4       1/8/10     V1      3      7     3       THE OUTPUT SHOULD BE AS FOLLOWS:- DATE           M1                          M2           

DetailsView edit problem after changing database

Hello!I had a DetailsView control for editing records in a Access 2003 database. I transfered the database to MS SQL 2008 and using the same code does not work - after clicking edit nothing happens (no error) and the record is not updated.ASP code:<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <h2> Urejanje kontaktnih podatkov </h2> <p> <asp:TextBox ID="txtKontaktID" Visible="false" runat="server"></asp:TextBox> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:conKrik %>" ProviderName="<%$ ConnectionStrings:conKrik.ProviderName %>"  SelectCommand="SELECT tblKontakt.*, tblStranka.strSkrajsanNaziv FROM krik.tblKontakt INNER JOIN krik.tblStranka ON tblKontakt.StrankaID = tblStranka.StrankaID WHERE ([KontaktId] = @id)" UpdateCommand="UPDATE tblKontakt SET strIme = @strIme, strPriimek = @strPriimek, strPoslovnaEnota = @strPoslovnaEnota, strTelefon = @strTelefon, strFaks = @strFaks, strMobitel = @strMobitel, strEmail = @strEmail, rmkOpomba = @rmkO

dynamically populating the database in the dropDownlist using c# in asp.net


hi everyone , plz listen my question very carefully

i have 2 tables  Desgn & EmpForm

Desgn table is lik this

CREATE TABLE [dbo].[Desgn](
    [DesignationCode] [int] IDENTITY(1,1) NOT NULL,
    [DesignationName] [varchar](50) NOT NULL,
    [DesignationCode] ASC

EmpForm table is like this

CREATE TABLE [dbo].[Empform](
    [EmpId] [varchar](50) NOT NULL,
    [EmpName] [varchar](50) NOT NULL,
    [EmpSalary] [numeric](18, 0) NULL,
    [EmpDesignationcode] [numeric](18, 0) NOT NULL,
    [EmpDateofBirth] [date] NOT NULL

now my ques is i want to dynamically populate the dropdown list of designation on the basis of the code but instead of code name should get populated .i have written the code like this 

public void Populate1()
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["co

Dynamically Generate No of Control(like Label) depend upon database no of item


I have a requirment like 

i required a dynamically generated Control (like Label) depend upon Database no of item


  If i fetch Database text (like Name) fieldd 3 time than i am intrested to generate  label 3 time

for (int i=0;i<table.row.count;i++)


label label[i]=table.row[i][0].Tostring();


How can do the above because label[i] is not allowed

Khurram Shahzad

Unable to create table dynamically in database


I am able to create database through script generated by SQL Server 2008 but unable to create tables from generated script. Please indicate if any step is missing.


************* Code *******************

 public bool CreateAppTables(string DatabaseName, string ConnectionString)
        string DatabaseScript;
        DatabaseScript = Activity.readTextFile(HttpContext.Current.Server.MapPath(".") + "/functionalscripts/CreateTablesonly.sql");
        DatabaseScript = DatabaseScript.Replace("DatabaseNametoChange", DatabaseName);
        return ActionQueryDB(DatabaseScript, ConnectionString);


 public bool ActionQueryDB(string SQLStatement, string ConnectionString)
        //  SqlConnection cn;

        OleDbConnection cn = new OleDbConnection();

        cn.ConnectionString = ConnectionString;
            OleDbCommand cmd = new OleDbCommand();
            cmd.CommandText = SQLStatement;
            cmd.Connection = cn;

            return true;
        catch (Exception ex)

            return false;


****************** Contents of text file appe

ASPNetSQLProvider - Changing it from the default to a custom SQL Database




I am new to ASP.NET and need some help.


What I am trying to do is to create a login for a new site that I am developing, and I need the users etc to be contained within the SQLEXPRESS database that I am using.

Can someone please help me to work out how to point the default ASPNETSQLProvider to my SQL database and not the default APP_Data one?

I am using Visual Studio 2008 and SQLExpress 2005.

Many thanks,



Error Message: Configure Database after changing the IP of the pc


hi All

When i click on Central Administration, I get a error message as  Configure Database after i changed the IP address of the MS Server 2008 R2. If i delete Sharepoint databases from SqlServer 2010 and then configure the database again it works fine. Why it ask me to configure database when ever i change the Server IP address?

Bind Event Receiver to List Dynamically


Hey all, I've been working on a little application page that will give users the option to say whether a list should allow duplicate title entries.

I am able to pass the current list GUID to the application page using this:

<UrlAction Url="~site/_layouts/preventduplicates.aspx?List={ListId}"/>

within a custom action which I've added to the list settings. I'm kind of stuck now....


I'm not sure how to grab this GUID out of the url, and use it so I can bind the current list with my event receiver. Every example I've seen of binding has used a hard coded list name which is fine as an example, but isn't the best for real applications. Or is there a way to use the GUID to get the lists name which I can then pass to the spweb.Lists[var] ? Since I won't know the list name beforehand.

Hope all of that makes sense, any suggestions are appreciated.

Bind combox, ListBox to SQL database column


Hi everyone

  I am having problem where I want to bind a column of the database to the Combobox so that Item of the combobox are present in the database

for example I have a table named Animals which is in the following format

ID   Animal

1    Dog

2    Cat

3    Horse

4   Goat


So the Item of the Combobox are Dog, Cat, Horse and Goat.  I had tried to bind the database to ObservableCollection First and then bind that ObservableCollection to the combobox.

   public class NameList : List<PersonName>
	private LikesLINQDataContext newlikes = new LikesLINQDataContext();

	List<string> depart = new List<string>();

	 public NameList(): base()
		foreach (var lol in newlikes.Likes)

		foreach (stri

Dynamically changing the Style of TreeViewItem



I am currently setting the style to the Treeview control inside Treeview.Resources which works fine. I need to change the Style dynamically when user changes selection in another control. Any thoughts on how this can be done?

Here is my current working code.

<TreeView Name="NavigationPaneTreeView" SelectedItemChanged="NavigationPaneTreeViewSelectedItemChangedEventHandler"



Dynamically display images from SQL database


I've found several good examples of how to display an image from a database, but I'm looking for an example of how to display an image within an aspx page with other controls.  This code works fine, but only displays the image by itself on the page (item4 is the image data, stored in SQL Server as type=Image):

Stream strmImage = new MemoryStream(item4.Image_Data.ToArray());
byte[] buffer = new byte[4096];
int byteSeq = strmImage.Read(buffer, 0, 4096);
while (byteSeq > 0)
    Response.OutputStream.Write(buffer, 0, byteSeq);
    byteSeq = strmImage.Read(buffer, 0, 4096);

I've also tried to save the data as a System.Drawing.Image, but like using the Response.Outputstream instruction above, it immediately outputs the image and nothing else on the page.

System.Drawing.Image myImage = System.Drawing.Image.FromStream(strmImage);
myImage.Save(Context.Response.OutputStream, ImageFormat.Jpeg);

In simple terms, I want to get the image from the database, stick it in a variable or something like that, then display it in a table.  Any suggestions?



Dynamically Changing ImageUrl in HyperLink control


Hey guys,

C#/.net newb alert. ;)

I'm writing a script and need help with being able to modify the ImageUrl property in a HyperLink control from the code behind page. It is meant to dynamically show an image.

I just need to know the correct format of the code behind to get this to work.


How to bind text containing HTML and ASP.NET tags from database



I have to show dynamic charts to clients.

I created table: ChartCodes

ChartCodeID     Code

1                      <asp:SqlDataSource ID='SqlDataSource_Chart1' runat='server' ConnectionString='<%$ ConnectionStrings:ConnectionString %>' SelectCommand='Usp_GetTotalEmissions_Org_chart' SelectCommandType='StoredProcedure'><SelectParameters>< . . .. . . . .

I wrote code of chart with sqldatasource in database column.

My problem is I could not able bind. I used DataList Control with a template and literal.

Bind literal with <%# Eval("Code") %>

But In sql I have ASP.NET tags <%  %>.   and when processing process %>, it assumes asp.net ends and wrote other text as it is in out put.

Please help me to find how to bind this text. Or any other Idea to display graphs from database as per user selection.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend