寫入

SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=mydata;User Id=sa;Password=1234");
conn.Open();
try
{


SqlCommand cmd = new SqlCommand("Insert Into Member_Detail(Account_Name,Password,Name,NickName,Sex,Birthday,CellPhone,[E-mail]) values(@paramAc,@paramPa,@paramNA,@paramNick,@paramSex,@paramBd,@paramCP,@paramEm) ", conn);
cmd.Parameters.Add("@paramAc", SqlDbType.NVarChar).Value = TextBox2.Text;
cmd.Parameters.Add("@paramPa", SqlDbType.NVarChar).Value = TextBox3.Text;
cmd.Parameters.Add("@paramNA", SqlDbType.NVarChar).Value = TextBox5.Text;
cmd.Parameters.Add("@paramNick", SqlDbType.NVarChar).Value = TextBox6.Text;
cmd.Parameters.Add("@paramSex", SqlDbType.NVarChar).Value = DropDownList2.Text;
cmd.Parameters.Add("@paramBd", SqlDbType.NVarChar).Value = TextBox7.Text + TextBox8.Text + TextBox9.Text;
cmd.Parameters.Add("@paramCP", SqlDbType.NVarChar).Value = TextBox10.Text;
cmd.Parameters.Add("@paramEm", SqlDbType.NVarChar).Value = TextBox11.Text;
cmd.ExecuteNonQuery();

Server.Transfer("LogIn.aspx");

/* SqlCommand aa = new SqlCommand("Select * From Member_Detail", conn);
SqlDataReader dr = aa.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();

cmd.Dispose();*/

 

}
catch
{
Label1.Text = "Error";
}
finally
{

conn.Close();
conn.Dispose();
}

 

更新

SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=mydata;User Id=sa;Password=1234");
conn.Open();

SqlCommand cmd = new SqlCommand("Update Member_Detail Set Name=@paramNa,NickName=@paramNick,Sex=@paramSex,Birthday=@paramBd where Account_Name='" + Session["Account_Name"] + "'", conn);
cmd.Parameters.Add("@paramNA", SqlDbType.NVarChar).Value = TextBox2.Text;
cmd.Parameters.Add("@paramNick", SqlDbType.NVarChar).Value = TextBox3.Text;
cmd.Parameters.Add("@paramSex", SqlDbType.NVarChar).Value = DropDownList2.Text;
cmd.Parameters.Add("@paramBd", SqlDbType.NVarChar).Value = TextBox7.Text + TextBox8.Text + TextBox9.Text;
cmd.ExecuteNonQuery();
conn.Close();
cmd.Dispose();

Server.Transfer("UpdateMDetail.aspx");

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Kent 的頭像
    Kent

    初學者做網站

    Kent 發表在 痞客邦 留言(0) 人氣()