JBTALKS.CC

标题: c# 问题 sql.. [打印本页]

作者: 135814048    时间: 2011-1-19 03:17 PM
标题: c# 问题 sql..
本帖最后由 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??不会弄=.='..




欢迎光临 JBTALKS.CC (https://jbtalks.my/) Powered by Discuz! X2.5