- 分享
- 0
- 人气
- 0
- 主题
- 8
- 帖子
- 114
- UID
- 115966
- 积分
- 216
- 阅读权限
- 14
- 注册时间
- 2007-12-20
- 最后登录
- 2013-10-7
- 在线时间
- 53 小时
|
本帖最后由 135814048 于 2011-1-19 03:18 PM 编辑
var cn = new SqlConnection();
cn.ConnectionString = @"Data Source=.;AttachDbFilename=C:\Users\Yoshimi\Documents\Visual Studio 2010\WebSites\WebSite1\App_Data\Database.mdf;Integrated Security=True;User Instance=True";
cn.Open();
var Ucheck = new SqlCommand();
Ucheck.Connection = cn;
Ucheck.CommandText = "SELECT username FROM member WHERE(username = '" +TextBoxUsername.Text+ "')";
var dr = Ucheck.ExecuteReader();
if (dr.HasRows)
{
cn.Close();
Response.Write("sudah ada username");
}
else
{
cn.Close();
cn.Open();
var cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "INSERT INTO member(username,password,e_mail,fristname,lastname,gander,reg_date)VALUES('" + TextBoxUsername.Text + "','" + TextBoxPassword.Text + "','" + TextBoxEmail.Text + "','" + TextBoxFristname.Text + "','" + TextBoxLastName.Text + "','" + RadioButtonList1.SelectedItem + "','" + DateTime.Now + "')";
cmd.ExecuteNonQuery();
cn.Close();
}
如果这样有什么问题吗?
还有怎样把sql connection 塞去class??不会弄=.='.. |
|