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


Top 5 Contributors of the Month
ASPEvil
Jean Paul
SP
satyapriyanayak
Ashutosh Jha
Post New Web Links

Create/add table from code to database

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net
 

Hi,

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


View Complete Post


More Related Resource Links

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


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.

 

Xinguo


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 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;
        try
        {
            cn.Open();
            OleDbCommand cmd = new OleDbCommand();
            cmd.CommandText = SQLStatement;
            cmd.Connection = cn;
            cmd.ExecuteNonQuery();
            cn.Close();

            return true;
        }
        catch (Exception ex)
        {

            cn.Close();
            return false;
        }
    }

 

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

Create a XML file from Database table using Dataset

  

HI,

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:

<contact>

     <name> John</name>

    <address> 100 main street </address>

...

</contact>

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:

"CREATE TABLE myTable" + "(myId INTEGER CONSTRAINT PKeyMyId PRIMARY KEY," + "myName CHAR(50)"

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.

Create new sql table at runtime VB.Net

  

I want to create a new table to sql database at runtime.  The column names would be "Name", "Date", "Event".  I would also like to have one more column name "Image" but the problem is that since the amount of images will vary, I want the application to count the amount of files in the Multiple fileuploader and then add a image column to the table for the respected amount of files. 

For example if i am uploading 3 files in the multiple fileuploader, the names should be "Name", "Date", "Event", "Image1", "image2", Image3"

I also would like that table name to be name dynamically from the textbox Name when the user enters the information.


I have the following code to make a new table, but I dont know how to name the fields at runtime like previously asked please help!!!


Dim objConn As New SqlConnection("Server=<servername>;uid=<userid>;pwd=<password>;database=master")

objConn.Open()

Can this code be setup to run against the whole database instead of just 1 record at a time?

  

We have made some changes to this code to start capturing 1 new field of data and updating it as new records are added. But there is currently about 120,000 records more or less.. those records of course dont have the new field populated with anything..

We would like to run this logic that already in place and run it against the tables to update the fields 1 time. I think to make it easier, if it can be setup to expect the "valueTwo" variable, so that we can run it againt the individual codes instead of doing all the records at one time.. there are codes that only have a few records, so it would be best to test initially against the small code group.

thanks.

  
            strSqual = "insert into trans (trans_type_name, trans_date,sys_id,mod_user_id,show_ind, remoteCode, techName) values('" & valueTwo & "','" & TransDate & "',"&strSystemID&", 1,'T', '" & dbQuote(strUser) & "', '" & strTechName & "')"        
  
            getStaticRecordSet(strSqual)   
            'get the new transaction_id out for just inserted alarm   
            strSqual = "select max(transaction_id) as transaction_id from trans"  
            set rst = getStaticRecordSet(strSqual)

how create database?????

  

I want to make databas? that will send daily to all members that leave email?Please if you can help me


Data Points: Windows Azure Table Storage - Not Your Father's Database

  

Let go of your traditional relational database thinking if you want to understand how Windows Azure Table storage works, says Julie Lerman. Luckily for you, she's done the hard work to grasp the new concepts and help you get up to speed.

Julie Lerman

MSDN Magazine July 2010


Toolbox: Database Audit Logs, Joel on Software, Code Handouts, and More

  

This month the Toolbox column takes a look at database logging, Joel Spolsky's blog, printing code projects, and ASP.NET reading.

Scott Mitchell

MSDN Magazine May 2008


Categories: 
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