.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

creating sql table from code c#

Posted By:      Posted Date: October 14, 2010    Points: 0   Category :ASP.Net

Hello i want that site manager will create his own tables in the Database in 2 steps!!! the first one is to create table in the database the user can choose the name of the new table by textbox and the table get only one ID column:

SqlConnection newCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            String st = "CREATE TABLE DataBaseConn.dbo." + tableName.Text.Trim()
                + "(contactId INTEGER PRIMARY KEY IDENTITY)";
            SqlCommand newCmd = new SqlCommand(st, newCon);

in the next step i want the user will add/insert the columns to the table (one column each time) the user will have textbox for the column name, drop down list with few kind of data type (datetime, int, varchar) and after press button the column will add to the table. ANY IDEA?????

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

Creating Event Handler in Code behind


Hi, so I have a control that is created in the code behind and generates fine but I can't figure out how to create an event handler for it.  I've found plenty of examples for it in C sharp, but none of them seem to apply to VB.  What I want to do is essentially this:

myDropDownList.SelectedIndexChanged = "Event to do here"

but it doesn't seem to work for me.

Any suggestions are appreciated.

creating a code based on the evaluation


I would like to create a simple program, like a game, but so far without any graphical interface. Only a code, supported with some numbers, so that the user will know whats going on in the background.

I was thinking of creating a racing game (like formula 1 or sometihng similar), with available data (attributes) like:

Driver: age, agility, concentration, experiance, stamina,...

Car: engine, chassis, tyres

Under the Table: How Data Access Code Affects Database Performance


In this article, the author delves into some commonly used ways of writing data access code and looks at the effect they can have on performance.

Bob Beauchemin

MSDN Magazine August 2009

Smart Tags: Realize the Potential of Office 2003 by Creating Smart Tags in Managed Code


While you may well be excited about the prospect of building managed smart tags, there is little information available to help you create them using .NET. In this article the author fills in the blanks. Along the way he discusses the Microsoft Office Smart Tag List XML schema, advanced managed smart tags for Office 2003 and Office XP, and deploying these features in an organization.

Ben Waldron

MSDN Magazine February 2005

Cutting Edge: Creating a Multi-table DataGrid in ASP.NET


If you bind a multi-table DataSet to a DataGrid, only the first table is recognized. Here Dino Esposito writes a custom solution the the multi-table problem.

Dino Esposito

MSDN Magazine August 2003

Creating a table-valued function on a user defined type in SQL Server CLR

We would like to be able to create a table-valued function on a user defined type.  We would like the syntax in SQL to look like it works for the XML nodes function:   DECLARE @myXml XML = '<a><b>1</b><b>2</b><b>3</b></a>' ; SELECT  node.query('text()') FROM    @myXml.nodes('a/b') nodes (node) ;   In other words, in the FROM clause, we can access the "nodes" method of the xml variable and it returns a rowset. Thanks!

Creating Code Function or Assemblies to manipulate Dataset

Folks In SSRS the dataset, can it be send to a Code function for further manipulation of the data ? For example, In SSRS I have a Column of Data and I want to passed it to a Code Function, and the code function for certain values and perform some Engineering calculation, and the function than return a modififed dataset. Can I do this ? Thanks in Advance  

InfoPath repeating table Copy values from above row without Code

Hi, I have situation, where I want to copy the values from the above row to the newly created row in a Repeating table. Ex. I have a repeating table with 3 columns ID-Name-FileName. When I enter a data like 1-Customer1-File1.zip and hit "Insert new row", the new row should automatically populate the values of the above row. How can I do it without .Net code. Regards,

Help creating HTML table from dataTable when every nth dataTable row = 1 html table row... C#

Hello, Im trying to create an html table from data that is in a dataTable but Im having trouble coming up with the right logic. Every 3 rows in the dataTable needs to be 1 row in the html table.  Ive tried using foreach through the datatable with a modulus to determin every third dataTable row but i still run into snags because i am building the table using objects rather than using concatenated strings..(example TableRow tr = new TableRow  etc...). I cant add the cells to the rows when the row is only created in an if statement etc. Can someone post a good example in c# of how they would achieve this. The amount of data in the dataTable could change from time to time so the code cant rely on a pre determined size, unless you just need the total rows and columns, that can be dtermined when the dataTable is filled from the sqlDataReader. <table><tr><td>dataTable row 1 values</td><td>ataTable row 2 values</td><td>dataTable row 3 values</td></tr> <tr><td>dataTable row 4 values</td><td>dataTable row 5 values</td><td>dataTable row 6 values</td></tr>   Any help and example would be great. Ive been able to do similar tables in other apps but thats only when I use concatenated text strings to build the html table. Im trying to stay away from that this time

Creating non-text ToolTips in code

I am trying to create a non-text ToolTip in my code like this (where sp is a StackPanel):                 if (helpText != null)                 {                     ToolTip tt = new ToolTip();                     RichTextBox rtb = new RichTextBox();                     rtb.Document = new FlowDocument(new Paragraph(new Run(helpText)));                     tt.Content = rtb;                     sp.ToolTip = tt;                 } This must be calling the ToString() method of the RichTextBox, because all I get in my ToolTip is "System.Windows.Controls.RichTextBox". Can you please tell me what I am missing? Thank you!

Creating table with database data, ASP.net and C#

Hi!I just started with my first ASP.net page with C# and I want to create a dynamic table with information from my database. I have connected to the database to the page with datareader, so that is solved. The problem is making the table and import the data into the different rows and columns. I also want the possibility to edit and remove this information from the table. Its supposed to be a table with information about customers.I have no idea whats the best solution for this and I hope you guys got information or links that show how to do this?Regards,fh01

Creating a Form say grid sort of a interface where in data values will be extracted from the table 4


how dis can be done help please with simple button click and changing the values it can be done but how to move columns with data in graceful manner the way we have in calendar control... 

Creating Table of consecutive dates


I'm trying to create a table with one field (SmallDate&Time)

I want this table to have consecutive dates beginning roughly 01/01/2008

through 12/31/2013.

I think I need a Stored procedure to do this but am not sure.

It may even be doable from an SQL Query.

Any help would be appreciated.









Can a table name impact generating the service client when creating Service Reference?


I have a new WCF service I'm writing under VS2010 and IIS 7.5.  The service includes a table named Client.

When I built my test class and added the service reference, the first test was confirming the creation of the client.

My service reference did not generate any client that I could call .Open on!!!! I was wondering if it is due to that table name???

 Edited to add that I tested the service through the browser and it brings up the page and XAML fine.

Thanks for any assistance!

Creating table records with foreign key constraints/Separate controllers?


I have multiple tables that are all linked back to a central table with foreign keys. I want to be able to create a new record in table 2, but I'm having trouble because I don't know how to create a new instance of table 2's record while referencing the ID of the record it will be tied to.


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