c# 2005-.sql2005  Adding a table

Posted on 2007-10-11
Last Modified: 2010-03-19
in c# 2005 how can i dynamically add a column to an  SQL table.  please include info to set the column parameters
Question by:the_b1ackfox
    LVL 9

    Author Comment

    PS  please include whatever options to set the primary key
    LVL 8

    Accepted Solution

    You need to execute an alter table sql statement:

    ALTER TABLE <table_name>
    ADD <column_name1> <datatype1> <constraint1>

    to add a primary key

    ALTER TABLE xx ADD primary key(<column>)

    Again, execute the sql commands using ADO.NET SqlCommand.ExecuteNonQuery.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now