제목 : 예제. 저장 프로시저를 사용한 Insert문(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 = "Insert CSharpTest Values('@Name')";
objCmd.CommandText = strSql;
objCmd.CommandType = CommandType.Text;
objCmd.Parameters.Add("@Name", SqlDbType.VarChar, 10);
objCmd.Parameters["@Name"].Value = "홍길동";
int intNum;
intNum = objCmd.ExecuteNonQuery();
objCon.Close();
Response.Write(intNum + "개의 데이터가 입력되었습니다.");
%>