제목 : 예제. SqlCommand 클래스를 사용한 Create문 실행(C#)
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%
SqlConnection objCon;
SqlCommand objCmd;
objCon = new SqlConnection();
objCmd = new SqlCommand();
string strCon = "server=localhost;database=dotnet;user id=dotnet;password=dotnet";
objCon.ConnectionString = strCon;
objCon.Open();
objCmd.Connection = objCon;
string strSql = "Create Table CSharpTest" +
"(Num int identity(1,1) Not Null, Name varchar(10) Null)";
objCmd.CommandText = strSql;
objCmd.CommandType = CommandType.Text;
objCmd.ExecuteNonQuery();
objCon.Close();
Response.Write("테스트용 테이블이 생성되었습니다.");
%>