c\#asp.net 동적 으로 sql 데이터베이스 테이블 을 만 드 는 방법

1961 단어 동태창설시계.

//
using System;
using System.Data;
using System.Data.SqlClient;
//
string tabName = "table1";
// , textbox ;
string sqlStr = "create table ";
sqlStr += tabName + "( ";
sqlStr += "col0 numeric identity(1,1) primary key,";
//col0 , textbox
//identity(1,1)
//primary key
sqlStr += "col1 varchar(20),";
sqlStr += "col2 smalldatetime,";
sqlStr += "col3 varchar(20),";
sqlStr += "col4 int,";
sqlStr += "col5 varchar(20),";
sqlStr += " )";

// sql
SqlConnection conn = new SqlConnection("server=.; database=dbName; uid=sa; pwd=sa");
conn.Open();
// sql
SqlCommand cmd = new SqlCommand(sqlStr, conn);
// sql
cmd.ExecuteNonQuery();
//
conn.Close();

제 코드:

       string tabName = "Job";
        string sqlStr = "create table ";
        sqlStr += tabName + "( ";
        sqlStr += "Id int identity(1,1) primary key,";
        //col0 , textbox
        //identity(1,1)
        //primary key

       sqlStr += "num int,";
        sqlStr += "Colour varchar(50),";

       sqlStr += "Other varchar(50),";
        sqlStr += " )";

       // sql
        string sss = "Data Source=(local);Initial Catalog=" + dataconnect + ";Integrated Security=True";
        SqlConnection conn = new SqlConnection(sss );
        conn.Open();

       // sql
        SqlCommand cmd = new SqlCommand(sqlStr, conn);

       // sql
        cmd.ExecuteNonQuery();

       //
        conn.Close();

좋은 웹페이지 즐겨찾기