问题描述
namespaceStudentManagementsystem{///<summary>///NewStu的摘要说明。///</summary>publicclassForm1:System.Windows.Forms.Form{privateSystem.Windows.Forms.Labellabel1;privateSystem.Windows.Forms.Labellabel2;privateSystem.Windows.Forms.Labellabel3;privateSystem.Windows.Forms.Labellabel4;privateSystem.Windows.Forms.Labellabel5;privateSystem.Windows.Forms.Labellabel6;privateSystem.Windows.Forms.Labellabel7;privateSystem.Windows.Forms.Labellabel8;privateSystem.Windows.Forms.Labellabel9;privateSystem.Windows.Forms.Labellabel10;privateSystem.Windows.Forms.Labellabel11;privateSystem.Windows.Forms.Labellabel12;privateSqlConnectionteamConn;privateSqlCommandteamComd;privatestringteamStrConn="workstationid=localhost;IntegratedSecurity=SSPI;database=c2p";privatestringteamstrsql;privateSqlDataAdapterteamsqlda;privateSystem.Windows.Forms.GroupBoxgroupBox1;privateSystem.Windows.Forms.GroupBoxgroupBox2;privateSystem.Windows.Forms.TextBox用户编号;privateSystem.Windows.Forms.TextBox真实姓名;privateSystem.Windows.Forms.TextBox性别;privateSystem.Windows.Forms.TextBox用户作品编号;privateSystem.Windows.Forms.TextBox用户等级;privateSystem.Windows.Forms.TextBox用户名;privateSystem.Windows.Forms.TextBox兴趣爱好;privateSystem.Windows.Forms.TextBox用户邮箱;privateSystem.Windows.Forms.TextBox用户所得积分;privateSystem.Windows.Forms.ComboBox用户所属团队;privateSystem.Windows.Forms.DateTimePicker用户注册时间;privateSystem.Windows.Forms.DateTimePicker出生年月;privateSystem.Windows.Forms.Button录入;privateSystem.Windows.Forms.Button退出;privateSystem.Windows.Forms.Button撤销;privatevoid录入_Click_1(objectsender,System.EventArgse){try{//stringdate=this.用户注册时间.Value.Date.ToString();;if(用户编号.Text=="")//保证学生姓名和入学日期必须得到填写{MessageBox.Show("用户编号必须填写!","提示");}else{DataSetteamname=newDataSet();//首先需要检索出用户所在的团队号才可以在学生表中进行插入新记录stringteamStrC+"'"+用户所属团队.SelectedItem+"'";teamConn=newSqlConnection(teamStrConn);teamsqlda=newSqlDataAdapter(teamStrConnSql,teamConn);teamname.Clear();teamsqlda.Fill(teamname);string团队圈名=teamname.Tables[0].Rows[0][0].ToString().Trim();//检索数据库内是否已经有同名的记录DataSetmember=newDataSet();stringExmember="select*fromuserinformationwhere用户编号="+"'"+用户编号.Text+"'";teamConn=newSqlConnection(teamStrConn);teamsqlda=newSqlDataAdapter(Exmember,teamConn);member.Clear();teamsqlda.Fill(member);if(member.Tables[0].Rows.Count==0){//在用户表中插入新纪录teamstrsql="Insertinto用户信息表(用户编号,用户名,真实姓名,出生年月,性别,兴趣爱好,用户注册时间,用户所属团队,用户等级,用户所得积分,用户作品编号,用户邮箱)Values('"+用户编号.Text;teamstrsql=teamstrsql+"','"+用户名.Text;teamstrsql=teamstrsql+"','"+真实姓名.Text;teamstrsql=teamstrsql+"','"+出生年月.Text;teamstrsql=teamstrsql+"','"+性别.Text;teamstrsql=teamstrsql+"','"+兴趣爱好.Text;teamstrsql=teamstrsql+"','"+用户注册时间.Text;teamstrsql=teamstrsql+"','"+用户所属团队.Text;teamstrsql=teamstrsql+"','"+用户等级.Text;teamstrsql=teamstrsql+"','"+用户所得积分.Text;teamstrsql=teamstrsql+"','"+用户作品编号.Text;teamstrsql=teamstrsql+"','"+用户邮箱.Text+"')";teamConn=newSqlConnection(teamStrConn);teamConn.Open();teamComd=newSqlCommand(teamstrsql,teamConn);intSuccnum=teamComd.ExecuteNonQuery();if(Succnum>0)MessageBox.Show("录入成功");}else{MessageBox.Show("录入信息重复。","确认");}}}catch{MessageBox.Show("该生已经录入或类型不匹配。","确认",MessageBoxButtons.YesNo);}}}}运行可以,可是没有实现插入,直接进入Catch语句
解决方案
解决方案二:
跟断点,调试一下,看是那的错。。。
解决方案三:
适配器的AcceptChange方法好像没看见
解决方案四:
catch你就是这么用的啊?把Exception的message也show出来啊