寫入
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=mydata;User Id=sa;Password=1234");
conn.Open();
try
{
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();
SqlDataReader dr = aa.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
cmd.Dispose();*/
}
catch
{
Label1.Text = "Error";
}
finally
{
catch
{
Label1.Text = "Error";
}
finally
{
conn.Close();
conn.Dispose();
}
conn.Dispose();
}
更新
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=mydata;User Id=sa;Password=1234");
conn.Open();
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();
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");
沒有留言:
張貼留言