用户登陆 ID=sa Pwd=sa@失败! 用户名或则密码不正确..... 

解决方案 »

  1.   

    try
    {
    //你登录的代码
    }
    catch(Exception ex)
    {
    messagebox.show(ex.message)
    }
      

  2.   

    源码:
    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 MySchool
    {
        public partial class creatStuForm : Form
        {
            public creatStuForm()
            {
                InitializeComponent();
            }        private void btnqux_Click(object sender, EventArgs e)
            {
                this.Close();
            }        private void btnsave_Click(object sender, EventArgs e)
            {            //获取要插入数据库的每个字段的值
                string loginId = txtuser.Text;  //用户名            string loginPwd = txtpass.Text; //密码
                //根据选择的状态设置状态Id,该Id值存放在控件的Tag属性中
                string status=rdoActive.Checked?(string)rdoActive.Tag:(string)rdoInactive.Tag;
                string stuName = txtname.Text;
                string stuNo = txtstuNo.Text;
                string stuPhone = txtphone.Text;
                string stuEmail = txtemail.Text;
                //性别
                string stuSex = rdoMale.Checked ? rdoMale.Text : rdoFemale.Text;
                //调用获取班级Id的方法,获取班级 Id
                int classId=GetClassId();
                //构建插入的sql语句
                string sql=string.Format(
                    "insert into student(loginId,loginPwd,status,classId,stuName,stuSex,stuPhonestuNo,stuEmail)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')",
                loginId,loginPwd,status,stuName,stuNo,stuPhone,stuEmail,stuSex,classId);
                //创建command对象
                try
                {
                    SqlCommand command = new SqlCommand(sql, DBHelper.conn);
                    DBHelper.conn.Open();
                    int result = command.ExecuteNonQuery();
                    if (result != 1)
                    {
                        MessageBox.Show("添加失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("添加成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception ex)
                {                MessageBox.Show("操作数据库出错!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Console.WriteLine(ex.Message);
                }
                finally {
                    DBHelper.conn.Close();
                }
                this.Close();
            }        private int GetClassId()
              {
                int classId=0;
                string sql = string.Format("select  classId from class where classname='{0}'",cboClass.Text);
               
                try
                {
                    //定义Command对象
                    SqlCommand command = new SqlCommand(sql, DBHelper.conn);
                    DBHelper.conn.Open();
                    SqlDataReader datareader = command.ExecuteReader();
                    //读出班级Id
                    if (datareader.Read())
                    {
                        classId = (int)datareader[0];                }
                    datareader.Close();
                }
                catch (Exception ex)
                {                MessageBox.Show("操作数据库出错!");
                    Console.WriteLine(ex.Message);
                }
                finally {
                    DBHelper.conn.Close();
                }
                return classId;
     
            }
        
        }
    }
      

  3.   

    不管其他,重新改下密码试试看
    EXEC sp_password NULL, '你的新密码', 'sa'
    可能你记错了呢
      

  4.   

    身份验证 需要SQLERVICE和WINDOWS 看看.