How to execute DROP/CREATE TABLE from c#?

  • Thread starter Richard Blewett [DevelopMentor]
  • Start date
R

Richard Blewett [DevelopMentor]

using System;
using System.Data;
using System.Data.SqlClient;

class App
{
static void Main(string[] args)
{
string SQL = @"Create table Foo
(
Bar int
)";
SqlConnection conn = new SqlConnection("server=.;integrated security=SSPI; database=pubs");

conn.Open();

SqlCommand cmd = new SqlCommand(SQL, conn);

cmd.ExecuteNonQuery();
}
}


Obviously you need the permissions in the database to be able to perform the operations

Regards

Richard Blewett - DevelopMentor

http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

How can I execute a DROP/CREATE TABLE statement from code using c#?

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004



[microsoft.public.dotnet.languages.csharp]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top