日期:2014-05-17  浏览次数:20970 次

C#编程 家庭理财系统 代码追踪学习
本帖最后由 chenjinglong 于 2013-09-20 18:36:47 编辑
登录实现 与SQL server链接
定义数据库连接类   
 
class DBHelper
    {
     private static string strSql = string.Format(@"server=CHENJINGLONGPC\SQLEXPRESS;database=FamilyFinace;Integrated Security=True");
     public static SqlConnection connect= new SqlConnection(strSql);
    }
登录系统
 try
                {
                    DBHelper.connect.Open();
                    string sql = string.Format(@"select count(*) from FamilyUser where UserName='{0}' and UserPassword='{1}'", txtUserName.Text.Trim(), txtPassWord.Text);
                    SqlCommand conform = new SqlCommand(sql, DBHelper.connect);
                    int result = (int)conform.ExecuteScalar();
                    if (result > 0)
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        lblUPError.Visible = true;
                    }

                    // MessageBox.Show("success");
                }