当前位置:编程学习 > C#/ASP.NET >>

师傅指导

namespace StudentManagementsystem
{
        /// <summary>
        /// NewStu 的摘要说明。
        /// </summary>
        public class Form1 : System.Windows.Forms.Form
        {
                private System.Windows.Forms.Label label1;
                private System.Windows.Forms.Label label2;
                private System.Windows.Forms.Label label3;
                private System.Windows.Forms.Label label4;
                private System.Windows.Forms.Label label5;
                private System.Windows.Forms.Label label6;
                private System.Windows.Forms.Label label7;
                private System.Windows.Forms.Label label8;
                private System.Windows.Forms.Label label9;
                private System.Windows.Forms.Label label10;
                private System.Windows.Forms.Label label11;
                private System.Windows.Forms.Label label12;
               private SqlConnection teamConn;
                private SqlCommand teamComd;
                private string teamStrConn="workstation id=localhost;Integrated Security=SSPI;database=c2p";
                private string teamstrsql;
                private SqlDataAdapter teamsqlda;
                private System.Windows.Forms.GroupBox groupBox1;
                private System.Windows.Forms.GroupBox groupBox2;
                private System.Windows.Forms.TextBox 用户编号;
                private System.Windows.Forms.TextBox 真实姓名;
                private System.Windows.Forms.TextBox 性别;
                private System.Windows.Forms.TextBox 用户作品编号;
                private System.Windows.Forms.TextBox 用户等级;
                private System.Windows.Forms.TextBox 用户名;
                private System.Windows.Forms.TextBox 兴趣爱好;
                private System.Windows.Forms.TextBox 用户邮箱;
                private System.Windows.Forms.TextBox 用户所得积分;
                private System.Windows.Forms.ComboBox 用户所属团队;
                private System.Windows.Forms.DateTimePicker 用户注册时间;
                private System.Windows.Forms.DateTimePicker 出生年月;
                private System.Windows.Forms.Button 录入;
                private System.Windows.Forms.Button 退出;
                private System.Windows.Forms.Button 撤销;               
              
                private void 录入_Click_1(object sender, System.EventArgs e)
                {

                        try
                        {
                                //string date=this.用户注册时间.Value.Date.ToString();;
                                if(用户编号.Text=="")//保证学生姓名和入学日期必须得到填写
                                {
                                        MessageBox.Show("用户编号必须填写!","提示");
                                }
                                else
                                {
                                        DataSet teamname=new DataSet();
                                        //首先需要检索出用户所在的团队号才可以在学生表中进行插入新记录
                                        string teamStrC+"'"+用户所属团队.SelectedItem+"'";
                                        teamConn=new SqlConnection(teamStrConn);                        
                                        teamsqlda=new SqlDataAdapter(teamStrConnSql,teamConn);
                                        teamname.Clear();
                                        teamsqlda.Fill(teamname);
                                        string 团队圈名=teamname.Tables[0].Rows[0][0].ToString().Trim();
                                
                                        //检索数据库内是否已经有同名的记录
                                        DataSet member=new DataSet();
                                        string Exmember="select * from userinformation where 用户编号="+"'"+用户编号.Text+"'";
                                        teamConn=new SqlConnection(teamStrConn);
                                        teamsqlda=new SqlDataAdapter(Exmember,teamConn);
                                        member.Clear();
                                        teamsqlda.Fill(member);
                                        if(member.Tables[0].Rows.Count==0)
                                        {
                                                //在用户表中插入新纪录
                                            teamstrsql="Insert into 用户信息表(用户编号,用户名,真实姓名,出生年月,性别,兴趣爱好,用户注册时间,用户所属团队,用户等级,用户所得积分,用户作品编号,用户邮箱) 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=new SqlConnection(teamStrConn);
                                                teamConn.Open();
                                                teamComd=new SqlCommand(teamstrsql,teamConn);
                                                int Succnum=teamComd.ExecuteNonQuery();
                                                if(Succnum>0) MessageBox.Show("录入成功");                                        
                                        }
                                        else
                                        {
                                                MessageBox.Show("录入信息重复。","确认");
                                        }
                                }
                        } 
                        catch
                        {
                                MessageBox.Show("该生已经录入或类型不匹配。","确认",MessageBoxButtons.YesNo);
                        }
                }                
        }
}
运行可以,可是没有实现插入,直接进入Catch语句 --------------------编程问答-------------------- 跟断点,调试一下,看是那的错。。。 --------------------编程问答-------------------- 适配器的AcceptChange方法好像没看见 --------------------编程问答-------------------- catch 你就是这么用的啊?
把Exception的message也show出来啊
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,