本文整理汇总了C#中DbConnection.DbConn方法的典型用法代码示例。如果您正苦于以下问题:C# DbConnection.DbConn方法的具体用法?C# DbConnection.DbConn怎么用?C# DbConnection.DbConn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbConnection
的用法示例。
在下文中一共展示了DbConnection.DbConn方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//DbConnection 인스턴스 초기화
DbConnection DbConn = new DbConnection();
SqlConnection conn = DbConn.DbConn();
////프로시저명
//string SpName = "SP_BoardList";
//SqlCommand cmd = new SqlCommand(SpName, conn);
//cmd.CommandType = CommandType.StoredProcedure;
////SqlDataReader 사용
//SqlDataReader objDr = cmd.ExecuteReader();
//this.List.DataSource = objDr;
//this.List.DataBind();
//SqlDataAdapter 사용
SqlDataAdapter da = new SqlDataAdapter("SP_BoardList", conn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
//DataSet 사용
DataSet ds = new DataSet();
da.Fill(ds, "BoardList");
List.DataSource = ds;
List.DataBind();
}
示例2: getView
protected void getView()
{
//DbConnection 인스턴스 초기화
DbConnection DbConn = new DbConnection();
SqlConnection conn = DbConn.DbConn();
//프로시저명
string SpName = "SP_BoardView";
SqlCommand cmd = new SqlCommand(SpName, conn);
cmd.CommandType = CommandType.StoredProcedure;
//파라미터 설정
cmd.Parameters.Add("@PK_BoardList", SqlDbType.Int);
cmd.Parameters["@PK_BoardList"].Value = Convert.ToInt32(Request.QueryString["ID"].ToString());
SqlDataReader objDr = cmd.ExecuteReader();
while(objDr.Read()){
lblKorName.Text = objDr[1].ToString();
lblEngName.Text = objDr[2].ToString();
lblJumin1.Text = objDr[3].ToString().Substring(0, 6);
lblJumin2.Text = objDr[3].ToString().Substring(6);
string BirthdayStr = objDr[4].ToString();
lblBirthday.Text = BirthdayStr.Substring(0, 4) + "년 " + BirthdayStr.Substring(4, 2) + "월 " + BirthdayStr.Substring(6) + "일";
if (objDr[5].ToString().Equals(1))
{
chkLunar.Checked = true;
}
else
{
chkLunar.Checked = false;
}
lblRepNo.Text = objDr[6].ToString().Substring(0, 3);
lblTelMiddleNo.Text = objDr[6].ToString().Substring(3, 4);
lblTelLastNo.Text = objDr[6].ToString().Substring(7);
string sexType = objDr[7].ToString();
if (objDr[7].ToString().Equals("M"))
{
lblSex.Text = sexType.Replace(objDr[7].ToString(), "남");
}
else
{
lblSex.Text = sexType.Replace(objDr[7].ToString(), "여");
}
lblReligion.Text = objDr[8].ToString();
lblMilitaryType.Text = objDr[9].ToString();
txtRemark.Text = objDr[10].ToString();
}
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
//DbConnection 인스턴스 초기화
DbConnection DbConn = new DbConnection();
SqlConnection conn = DbConn.DbConn();
//대표변호 프로시저
SqlCommand cmdRepNo = new SqlCommand("SP_RepNo", conn);
cmdRepNo.CommandType = CommandType.StoredProcedure;
//Dropdownlist value 바인딩
SqlDataReader objDr = cmdRepNo.ExecuteReader();
ddlRepNo.DataSource = objDr;
ddlRepNo.DataTextField = "CODE_NM";
ddlRepNo.DataValueField = "CODE";
ddlRepNo.DataBind();
objDr.Close();
//종교 프로시저
SqlCommand cmdReligion = new SqlCommand("SP_Religion", conn);
cmdReligion.CommandType = CommandType.StoredProcedure;
objDr = cmdReligion.ExecuteReader();
ddlReligion.DataSource = objDr;
ddlReligion.DataTextField = "CODE_NM";
ddlReligion.DataValueField = "CODE";
ddlReligion.DataBind();
objDr.Close();
//군별 프로시저
SqlCommand cmdMilitaryType = new SqlCommand("SP_MilitaryType", conn);
cmdMilitaryType.CommandType = CommandType.StoredProcedure;
objDr = cmdMilitaryType.ExecuteReader();
ddlMilitaryType.DataSource = objDr;
ddlMilitaryType.DataTextField = "CODE_NM";
ddlMilitaryType.DataValueField = "CODE";
ddlMilitaryType.DataBind();
objDr.Close();
ddlMilitaryType.Items.Insert(0, "해당없음");
}
}
示例4: btnSave_Click
protected void btnSave_Click(object sender, EventArgs e)
{
//DbConnection 인스턴스 초기화
DbConnection DbConn = new DbConnection();
SqlConnection conn = DbConn.DbConn();
////프로시저명
string SpName = "SP_BoardWrite";
SqlCommand cmd = new SqlCommand(SpName, conn);
cmd.CommandType = CommandType.StoredProcedure;
//파라미터 설정
cmd.Parameters.Add("@NM_KOR", SqlDbType.NVarChar, 10);
cmd.Parameters.Add("@NM_ENG", SqlDbType.NVarChar, 100);
cmd.Parameters.Add("@Jumin_NO", SqlDbType.Char, 13);
cmd.Parameters.Add("@Birthday", SqlDbType.VarChar, 8);
cmd.Parameters.Add("@Lunar_CHK", SqlDbType.Bit);
cmd.Parameters.Add("@Phone_NO", SqlDbType.VarChar, 11);
cmd.Parameters.Add("@Sex", SqlDbType.Char, 1);
cmd.Parameters.Add("@Religion", SqlDbType.VarChar, 4);
cmd.Parameters.Add("@Military_TYPE", SqlDbType.VarChar, 4);
cmd.Parameters.Add("@Remark", SqlDbType.NVarChar, 1000);
cmd.Parameters["@NM_KOR"].Value = txtKorName.Text;
cmd.Parameters["@NM_ENG"].Value = txtEngName.Text;
cmd.Parameters["@Jumin_NO"].Value = txtJumin1.Text + txtJumin2.Text;
cmd.Parameters["@Birthday"].Value = txtBirthday.Text;
cmd.Parameters["@Lunar_CHK"].Value = chkLunar.Checked;
cmd.Parameters["@Phone_NO"].Value = ddlRepNo.SelectedItem.Text + txtTelMiddleNo.Text + txtTelLastNo.Text;
cmd.Parameters["@Sex"].Value = RadioBtnSex.SelectedValue;
cmd.Parameters["@Religion"].Value = ddlReligion.SelectedValue;
cmd.Parameters["@Military_TYPE"].Value = ddlMilitaryType.SelectedValue;
cmd.Parameters["@Remark"].Value = txtRemark.Text;
cmd.ExecuteNonQuery();
conn.Close();
cmd = null;
string script = "<script>alert('저장되었습니다');</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "saveScript", script);
Response.Redirect("BoardList.aspx");
}