首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#编程 家庭理财系统 代码跟踪学习

2013-09-25 
C#编程 家庭理财系统 代码追踪学习本帖最后由 chenjinglong 于 2013-09-20 18:36:47 编辑登录实现 与SQL s

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");
                }



                catch (SqlException ex)
                {
                    MessageBox.Show("登录失败 原因如下" + ex.Message, "家庭理财管理系统");
                }
                finally
                {
                    DBHelper.connect.Close();
                }
            



你可以写在博客中。。

热点排行