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

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

Unable to create table dynamically in database

Posted By:      Posted Date: September 26, 2010    Points: 0   Category :ASP.Net

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

View Complete Post

More Related Resource Links

Create/add table from code to database



I create table:

                  DataSet data=new DataSet();

                  DataTable myTable = new DataTable("NewTable");

                   DataColumn[] keys = new DataColumn[1];

                   // create column
                   keys[0] = new DataColumn();
                   keys[0].DataType = System.Type.GetType("System.String");
                   keys[0].ColumnName = "PointID";
                   myTable.Columns.Add(keys[0]);    &nb

Create table in the database using management studio


 I have database already on the server. However, when I created new table, the new created table Schema is not dbo. it is my user name. How to solve this?

It shows the new created table Schema is my username but not dbo.

Even though I rename it, it couldn't change. I can see this in table property.



Want to Create Table Dynamically With text Control in WinForm Csharp

Hello To All... from Many Days i m tryng to create a simple table using csharp in WinForm.Which will include textbox in each cell according the Passed No of Col & Row. but not getting the proper result. Actually i want to trace each cell data and want to save each cell data to data base : eg. in cell 11(1col & 1row) i m having Combobox which having some item list and when the user select the list item the data will save to the database. Regards, Praveen    What is the Key of Life ... Its Sharing Your Thought & Knowledge ...

How to create a view in my database from a table in another server/database

Is there a way to create a view in my database referencing a table in another server/database if I have the connection information.  I know how to do it in Oracle, simply create a database link, but have never done so in sqlserver.

unable to create new table in sql server 2000 enterprise manager on windows7(Operating system)

i have successfuly installed sql server 2000 on windows7 and i am able to browse all the tables and edit aswell(on enterprise manager) but i have a problem while creating new tables it says ' MMC has detected an error in a snap-in' and provides options to either continue with the error or send a report to microsoft ,   Please help regarding this compatibility issue   Thanks in advance !

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!

Create table dynamically in SQL Server


hi all,

i want to create temparory table dynamically in sql server,

well, it depends on the fields that are passed from front end as comma seprated value..

and that table shoud contain only that fields that are passed  from front end,

help me on this if it is possible,


Thanx in advance,

Sagar Joshi

I am unable to create dynamic menu from database


Hi Expert,

I am unable to create dynamic menu from database. I have made two tables for this work.

First table is Menu which stores menu id and its relevant name.
MId Text
1 File
2 Edit
3 View

Second table is subMenu which stores submenus which will be linked to the menu table with menu id.

SId Text MID
1 New 1
2 Open 1
3 Save 1
4 Cut 2
5 Copy 2

the menu should be created dynamically from the database, each menu should be displayed in single row

when we click on a menu the submenus are displayed in rows that in expand & contrast form

how to design & develope this page

How to create a Table of content in .rdl design in BIDS dynamically according to the Page no wise..?



well i am able to create the TOC statically by using the Document Map properties as describe in my older post issue 

but now i just want to create the Table of contents dynamically generate using the page no wise..is it possible...how can we do it while designing the .rdl in BIDS..



SSIS 2005 - Dynamically generate create table statement from source



I have a requirement where i had to migrate the table structure and data from ODBC database to SQL Server. I have dynamic source reader that uses sql query from variable to get the data and the next step is to get the create statement and create table and then to insert data. how can i get Create Statement the destination produces and use sql task to create the table and then insert the data using data flow task.

Please suggest



Unable to create database in particualr folder


When i am trying to create a database in Sql Server in my PC, i am not allowed to create database in a particular folder. It gives an error saying that,

Msg 1802, Level 16, State 4, Line 1

CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

Msg 5123, Level 16, State 1, Line 1

CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Program Files\Test\Database\CheckCreation.mdf'.

I am having the administrator access in that PC but still not allowed.

I am able to create it in all other folders.

Can anyone help me in this issue?

Thanks & Regards,
Subalakshmi Vijayarajan.

Create a XML file from Database table using Dataset



I've got a SQL database with a table named contact with different column such Name, Address, email ...

I would like to generate a XML file based on the table data:


     <name> John</name>

    <address> 100 main street </address>



After some research it looks like I can use a dataset from that table to create my xml.

Being a beginner I cannot find the right steps / syntax to do so.

Is there any tutorial showing how to work with dataset and XLM?

Thank you for your helps 


Create DataBase Table Question


I am creating a table in a database in SQL Express and found the following example:


I''m confused at the Key word Constraint followed by PKeyMyID.  A table get created with myId and myName columns.  What is the CONSTRAINT PKeyMyID for?

Dennis in Longview

Can not create table via SSMS 2008 database designer (GUI) even with db_ddladmin role


I have SSMS 2008 (version - 10.0.2531.0)
Back end Microsoft SQL Server 2008 (SP1) - 10.0.2723.0 (X64)
I have DB_ddlAdmin role on a database

I can create/alter a table via sql script.
In the SSMS Database Designer (GUI), When I right click on the database >> Tables and select New Table I get the following error.
"You are not logged in as Database Owner or System Administrator. You might be able to save chnages..."

Then i get a screen where SSMS asks me to enter column names. When I enter column names and I can click on Save I get "Not a Table Owner" error. The table does get created but after that i can not alter it via Database designer (I can alter it via a alter SQL).

So Long story short, I can create tabels via DDL sql but not via the SSMS database designer. This from a technical view point might not be a big deal but for a business person not knowing SQL syntax will be a critical issue.

This was reported back on 06/2009 but can't imagine it still being a active bug

Export Visio Database Table Names to Excel

If you use the Enterprise Architect edition of Microsoft Visio for data modeling regularly, then there is a good chance that at some point you've wanted to export just the table names into Excel. You might want to do this to map logical ERD entities to physical data model tables, track project status by entity, or track overlap between database versions.

Connestion string create any database server

This links important to how to create connection string to any data base sever.

Dynamically Create Controls in ASP.NET by Using Visual C# .NET

This article demonstrates how to dynamically create a control for an .aspx page. The sample project does the following:
Creates two TextBox controls.
Verifies that the contents (TextBox.text) and the attributes of the TextBox are saved across posts to the server.
Illustrates handling events that are posted by a dynamically-created control
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