问题是关于我代码中未处理的异常

时间:2019-04-11 13:12:33

标签: c# asp.net webforms

我正在尝试插入在场或不在场的学生的记录,但是每当我单击“保存”按钮时,都会出现此错误

  

System.Data.dll中发生类型为'System.Data.SqlClient.SqlException'的异常,但未在用户代码中处理

     

其他信息:无效的列名'F16BB120'。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label3.Text = "Mark Attendance for" + DateTime.Now.ToShortDateString();
    }

    //this my code which i am using to save data to my table 
    protected void Button2_Click(object sender, EventArgs e)
    {
        foreach(GridViewRow row in GridView1.Rows)
        {
            string stdrollNo =row.Cells[0].Text;
            string stdname = row.Cells[1].Text;
             RadioButton rbtn1 = (row.Cells[2].FindControl("RadioButton1") as RadioButton);
            RadioButton rbtn2 = (row.Cells[2].FindControl("RadioButton2") as RadioButton);
            String status1;
            if (rbtn1.Checked)
            {
                status1 = "Present";

            }
            else
            {
                status1 = "Absent";
            }
            String DateOfCalss = DateTime.Now.ToShortDateString();
            String batch = DropDownList1.SelectedItem.Text;
            String section = DropDownList1.SelectedItem.Text;
            saveattendance(stdrollNo, stdname, DateOfCalss, status1,batch,section);
        }
        Label4.Text = "Attendance Has Been Saved Successfully";
        }
    private void saveattendance(String stdrollNo,String studentname,String DateOfCalss,String status,String Batch,String Section)
    {
        String query = "insert into StudentAttendance(stdRollNo,stdName,DateOfCalss,Status,Batch,Section) values(" + stdrollNo + ",'" + studentname + "','" + DateOfCalss + "','" + status + "','" + Batch + "','" + Section + "')";
        String mycon = "Data Source=ADMIN-PC\\SQLSERVER; Initial Catalog=AttendanceSystem; Integrated Security=SSPI";
        SqlConnection con = new SqlConnection(mycon);
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = query;
        cmd.Connection = con;
        cmd.ExecuteNonQuery();

    }
    }

0 个答案:

没有答案