谢谢!

解决方案 »

  1.   

    如果你的登陆窗口是个dll就把用户名和密码作为一个结构或者一个类返回  
     如果是一个普通的模态窗口,把用户名密码直接作为属性让父窗口读取就行了
      

  2.   

    我觉得也是写一个xml或者是ini文件里吧。像QQ那种软件一样咯。如果是全局变量的话,不怎么好控制吧。
      

  3.   

    很简单啊。在项目上选属性,打开设置页,增加 如username string型;password string型。
    然后在登录窗口中,
    //加载上次登录用户
    txbUserName.Text = Properties.Settings.Default.username ;//登录成功,保存本次登录用户
    Properties.Settings.Default.username = txbUserName.Text;
    Properties.Settings.Default.Save();
    密码同样处理即可。
      

  4.   

    要看是winForm还是webForm了,
    winForm用全局静态变量比较方便
    webForm用Session或Cookies比较好
      

  5.   

    直接写进文件里面撒,写入.txt也可以撒
      

  6.   

    真巧,我刚刚解决!
    在你数据库用户表里面加多一 bit类型的标示符列 默认值为0,checkbox.checked==true触发为1 下面是我不严谨的写法,可以作为参考。using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;namespace Mianbxs
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private  int i = 0;
            private void btnLogin_Click(object sender, EventArgs e)
            {
                bool isEmpty = CheckEmpty();  //判断用户和密码是否为空
                if (isEmpty == true)   //如果不为空
                {
                    Dbhelper conn = new Dbhelper();
                    string sql = "Select Count(*) from 用户 where 用户名='" + txtUserName.Text + "' and 密码='" + txtPassword.Text + "'";
                    SqlCommand cmd = new SqlCommand(sql, conn.cn);
                    conn.cn.Open();
                    int n = (int)cmd.ExecuteScalar();
                    conn.cn.Close();
                    if (n > 0)
                    {
                        //记住密码
                        Updatabs();
                        
                        //打开主窗口
                        MainForm mForm = new MainForm();
                        mForm.Show();
                        this.Hide();
                    }
                        else
                        {
                            i++;
                            if (i == 3)
                            {
                                MessageBox.Show("你已经三次输入用户和密码不正确");
                                this.Close();
                            }
                           
                            MessageBox.Show("用户或密码不正确");                    }
                  
             
                }
            }
            //验证用户是否为空
            public bool CheckEmpty()
            {
                bool f = true;
                if (txtUserName.Text =="")
                {
                    f = false;
                    lblNameError.Visible = true;    //让错误的lable显示
                    
                }
                else
                {
                    lblNameError.Visible = false;
                }
                //验证用户密码是否为空
                if (txtPassword.Text=="")
                {
                    f = false;
                    lblPswError.Visible = true;
                    
                }
                else
                {
                    lblPswError.Visible = false;
                }
                return f;
            }        private void btnRegist_Click(object sender, EventArgs e)
            {
                Registform rFrom = new Registform();
                rFrom.Show();
            }        //记住用户密码
            public void Updatabs()
            {
                if (ckbRemenber.Checked == true)
                {
                    Dbhelper con = new Dbhelper();
                    string sql = string.Format("update 用户 set 标识符=1 where 用户名='{0}';", txtUserName.Text.Trim().ToString());
                    SqlCommand cm = new SqlCommand(sql, con.cn);
                    con.cn.Open();
                    cm.ExecuteScalar();
                    con.cn.Close();
                }           
            }        //如果上次是记住用户和密码的,把上次记住的用户和密码显示到对应的文本中
            public void Showdata()
            {
                    Dbhelper con = new Dbhelper();
                    SqlCommand cm = new SqlCommand("select 用户名,密码 from 用户 where 标识符=1", con.cn);
                    con.cn.Open();
                    SqlDataReader sdr=cm.ExecuteReader();
                    if (sdr.Read())
                    {
                        txtUserName.Text = sdr["用户名"].ToString();
                        txtPassword.Text = sdr["密码"].ToString();
                        ckbRemenber.Checked = true;
                    }
                    con.cn.Close();
            }        private void Form1_Load_1(object sender, EventArgs e)
            {
                Showdata();     //显示记住的用户和密码
            }        private void ckbRemenber_CheckedChanged(object sender, EventArgs e)
            {
                if(ckbRemenber.Checked==false)
                {
                    Dbhelper con = new Dbhelper();
                    string sql = string.Format("update 用户 set 标识符=0 where 用户名='{0}';", txtUserName.Text.Trim().ToString());
                    SqlCommand cm = new SqlCommand(sql, con.cn);
                    con.cn.Open();
                    cm.ExecuteScalar();
                    con.cn.Close();
                }
            }    }
    }
      

  7.   

    上面的好友说得好   在数据库里的用户表增加一个字段 int 类型 做为标识符            唉……
     
                    思路也与上面的差不多
      

  8.   

     
    winForm用 配置文件
    webForm用Cookies密码别忘加密,哈不过你的提问也太简约了吧。
      

  9.   

    登录窗口,frmLogin
    public static string M_str_name;//登录名字
    public static string M_str_pass;//登录密码成功后赋值
    M_str_name = textbox1.Text;
    M_str_pass = textbox2.Text;其他窗体调用
    frmlogin.M_str_name
    frmlogin.M_str_pass
      

  10.   

    To:  piepiepie 按你说的,会生成一个config文件,可是根本保存不进去啊