C# winForm窗体的,连接数据库为SQLite
实现一个登录页,后台代码给个详细的?
分都给了

解决方案 »

  1.   

    http://topic.csdn.net/u/20080923/13/d567615a-abd5-4ede-a1f3-2d28264988cb.html实现登录和连接什么数据库没有什么直接的联系。根据你的思路来定。
      

  2.   

    连接字符串自己修改一下就行了
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.Sql;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Xml;namespace stserver
    {
        public partial class login : Form
        {
            public login()
            {
                InitializeComponent();
            }
            public bool islogin = false;        private void btn_submit_Click(object sender, EventArgs e)
            {
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(Application.StartupPath + "\\config.xml");
                    string connstr = doc.DocumentElement.SelectSingleNode("serverconnstr").InnerText;
                    string selectstr = "select top 1 id from admin where uid='" + txb_uid.Text + "' and pwd='" + txb_pwd.Text + "'";
                    SqlConnection conn = new SqlConnection(connstr);
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(selectstr, conn);
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        islogin = true;
                        dr.Close();
                        conn.Close();
                        conn.Dispose();
                        MessageBox.Show("您好," + txb_pwd.Text + "!,欢迎使用\n\n祝您工作愉快!", "欢迎", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                    else
                    {
                        dr.Close();
                        conn.Close();
                        conn.Dispose();
                        MessageBox.Show("登录失败!\n请检查您的登录用户名和密码是否正确。\n\n如果您忘记了自己的密码请联系技术部");
                        txb_uid.Text = "";
                        txb_pwd.Text = "";
                        txb_uid.Focus();
                    }
                    dr.Close();
                    conn.Close();
                    conn.Dispose();
                }
                catch
                {
                    MessageBox.Show("不能连接到服务器,请联系技术部","服务器故障",MessageBoxButtons.OK,MessageBoxIcon.Error);
                }
            }        private void btn_cancel_Click(object sender, EventArgs e)
            {
                Application.ExitThread();
            }
        }
    }
      

  3.   

    需要一个SQLite的引擎啊,有个System.Data.SQLite,添加到项目引用之后就可以用了,给你个简单的参考:
      SQLiteConnection mycon = new SQLiteConnection(@"data source=db\Person.db3");
      mycon.Open();
      SQLiteCommand cmd = mycon.CreateCommand();
      cmd.CommandText = @"select * from person";
      SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
      DataSet ds = new DataSet();
      da.Fill(ds);
      dataGridView1.DataSource = ds.Tables[0];
      mycon.Close();
      

  4.   

    装完SQLite后,添加SQLite命名空间using System.Data.SQLite,添加到项目引用之后就可以用了然后将我代码的SqlConnection等相关部分改为SQLiteConnection等就可以了:
      SQLiteConnection mycon = new SQLiteConnection(@"data source=db\Person.db3");
      mycon.Open();
      SQLiteCommand cmd = mycon.CreateCommand();
      cmd.CommandText = @"select * from person";
      SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
      DataSet ds = new DataSet();
      da.Fill(ds);
      dataGridView1.DataSource = ds.Tables[0];
      mycon.Close();
      

  5.   

    using (SQLiteConnection conn2 = new SQLiteConnection(connStr))
                {
                    conn2.Open();
                    using (SQLiteCommand cmd1 = new SQLiteCommand("", conn2))
                    {
                    }
                }login frmlogin = new login();
                if (login.ShowDialog() == DialogResult.OK)
                {
                    Application.Run(new main_form());
                }
    51aspx.com里
      

  6.   

      /// <summary>
            /// 登录系统
            /// </summary>
            private bool Login(string userName, string password)
            {
                mainForm = new FormMain();
                errorProvider1.Clear();
                bool success = false;
                mainForm.CurrentUser = mainForm.DatabaseAccess.VerifyUser(userName, password);
                if (mainForm.CurrentUser != null) { mainForm.Show(); this.Hide(); success = true; mainForm.WriteLog("用户登录成功...."); }
                else
                {
                    errorProvider1.SetError(cbbUserName, "登录发生错误,错误原因:\r\n  1、用户名或密码错误。请核对后重新登录。\r\n  2、数据库连接不可达,请检查网络连接。");
                }
                return success;
            }