未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中 用户登陆 ID=sa Pwd=sa@失败! 用户名或则密码不正确..... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try{//你登录的代码}catch(Exception ex){messagebox.show(ex.message)} 源码: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; } }} 不管其他,重新改下密码试试看EXEC sp_password NULL, '你的新密码', 'sa'可能你记错了呢 身份验证 需要SQLERVICE和WINDOWS 看看. ToolStrip的动态Button 求教 实时的抓捕线程状态? 盼求熟悉SQLDMO的大鸟解决 论坛里面没人会转png图片???不是吧 大虾在哪 c#摄像头编程 设置图像显示长宽以及保存格式 关于C#和Access数据库的问题 c++中结构体到C#中的转换.关于位的操作,做过的来指点点,谢谢个 谁知道选择dataGrid一行后发生的事件名叫什么呀 ????????????? 服务器错误。 我是刚刚接触C#的,请各位大虾一个问题 高手大哥请进>>>! 关于:SQLCONNECTIONSTRING连接字符串加密
{
//你登录的代码
}
catch(Exception ex)
{
messagebox.show(ex.message)
}
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;
}
}
}
EXEC sp_password NULL, '你的新密码', 'sa'
可能你记错了呢