ooooombps! 2021-07-06 00:11 采纳率: 66.7%
浏览 76
已采纳

C# “(”附近有语法错误

学校实训作业,求大神帮我看看,看了半天硬是没找到哪里出错了QAQ
ps:代码写的比较烂

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 考勤系统.主页功能
{
    public partial class 考勤规则添加 : Form
    {
        public 考勤规则添加()
        {
            InitializeComponent();
        }

        public string[,] stuInfo;//装学生学号(0,i),装卡号(1,i)
        public int peoplenum , forNum = 0;//peoplenum人数,fornum循环次数
        public DateTime t;

        private void button1_Click(object sender, EventArgs e)
        {
            string
            classname = classNameBox.Text,  //课程名称
            classs = classBox.Text,         //班级
            starttime = startTime.Text,     //考勤开始时间
            endtime = endTime.Text;         //考勤结束时间

            #region Box,text空值判断及提示
            if (classname.Equals(""))
            {
                MessageBox.Show("课程名称不能为空");
                return;
            }
            else if (classs.Equals(""))
            {
                MessageBox.Show("班级不能为空");
                return;
            }
            else if (starttime.Equals(""))
            {
                MessageBox.Show("开始时间不能为空");
                return;
            }
            else if (endtime.Equals(""))
            {
                MessageBox.Show("结束时间不能为空不能为空");
                return;
            }
            #endregion

           
            string connString = "server=DESKTOP-9S477HC;database=实训_考勤;uid=sa;pwd=2414902339";
            SqlConnection insertConn = new SqlConnection(connString);
            SqlConnection selectConn1 = new SqlConnection(connString);


            #region 查询班级人数,学号,卡号,放入peoplenum,二维数组stuInfo(2行n列,第一行学号,第二行卡号)
            selectConn1.Open();
            string selectInfo1 =
            "select count(class) " +//查询班级人数
            "from student " +
            "where class = @t1 ";

            SqlCommand selectInfoCMD1 = new SqlCommand(selectInfo1, selectConn1);
            selectInfoCMD1.Parameters.Add(new SqlParameter("@t1", SqlDbType.VarChar));
            selectInfoCMD1.Parameters["@t1"].Value = classs;
            SqlDataReader select1 = selectInfoCMD1.ExecuteReader();

            if (select1.Read())
            {
                peoplenum = int.Parse(select1[0].ToString());
                stuInfo = stuInfo = new string[2, peoplenum];

                selectConn1.Close();

                selectConn1.Open();
                string selectInfo2=
                "select student_num,card_id " +//查询学号与卡id
                "from student " +
                "where class = @t1 ";

                selectInfoCMD1 = new SqlCommand(selectInfo2, selectConn1);
                selectInfoCMD1.Parameters.Add(new SqlParameter("@t1", SqlDbType.VarChar));
                selectInfoCMD1.Parameters["@t1"].Value = classs;
                select1 = selectInfoCMD1.ExecuteReader();
                if (select1.Read())
                {
                    //classBox.Text = peoplenum.ToString();//测试
                    //startTime.Text = select1[0].ToString();
                    //endTime.Text = select1[1].ToString();

                    for (int i = 0; i < peoplenum; i++)
                    {
                        stuInfo[0,i] = select1[0].ToString();
                        stuInfo[1,i] = select1[1].ToString();
                    }
                }
                else
                {
                    MessageBox.Show("添加失败,请核对班级,课程,时间等信息!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("添加失败,请核对班级,课程,时间等信息!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            selectConn1.Close();
            #endregion

            insertConn.Open();
            string insertInfo =
            "insert into " +
            "(student_num,card_id,course,start,deadline,late,truant) " +
            "values " +
            "(@t1,@t2,@t3,@t4,@t5,@t6,@t7)";
            SqlCommand insertInfoCMD = new SqlCommand(insertInfo, insertConn);
            insertInfoCMD.Parameters.Add(new SqlParameter("@t1", SqlDbType.VarChar));
            insertInfoCMD.Parameters.Add(new SqlParameter("@t2", SqlDbType.VarChar));
            insertInfoCMD.Parameters.Add(new SqlParameter("@t3", SqlDbType.VarChar));
            insertInfoCMD.Parameters.Add(new SqlParameter("@t4", SqlDbType.VarChar));
            insertInfoCMD.Parameters.Add(new SqlParameter("@t5", SqlDbType.VarChar));
            insertInfoCMD.Parameters.Add(new SqlParameter("@t6", SqlDbType.VarChar));
            insertInfoCMD.Parameters.Add(new SqlParameter("@t7", SqlDbType.VarChar));

            for (int i = 0; i < peoplenum; i++)
            {
                insertInfoCMD.Parameters["@t1"].Value = stuInfo[0, i];//学号
                insertInfoCMD.Parameters["@t2"].Value = stuInfo[1, i];//卡id
                insertInfoCMD.Parameters["@t3"].Value = classname;
                insertInfoCMD.Parameters["@t4"].Value = starttime;
                insertInfoCMD.Parameters["@t5"].Value = endtime;
                t = Convert.ToDateTime(endtime);
                t = t.AddMinutes(5);
                insertInfoCMD.Parameters["@t6"].Value = t.ToString();
                t = t.AddMinutes(20);
                insertInfoCMD.Parameters["@t7"].Value = t.ToString();

                forNum += insertInfoCMD.ExecuteNonQuery();

                insertConn.Close();

                insertConn.Open();
                }


                if (forNum == peopleNum)
            {
                MessageBox.Show("考勤添加成功");
            }
            else
            {
                MessageBox.Show("考勤添加失败");
            }
            insertConn.Close();





        }
    
    }
}


img

  • 写回答

1条回答 默认 最新

  • hxycsdn9159 2021-07-06 09:24
    关注

    insert into student 表名丢了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改