Kindly tell me how to resolve this error?
An exception of type System.InvalidOperationException occurred in System.Data.dll but was not hand
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace qb
{
public partial class Student : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button_AddStudent_Click(object sender, EventArgs e)
{
string name = TextBox_StudentName.Text; // Scrub user data
string year = TextBox_StudentYear.Text;
string connString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
SqlConnection conn;
conn = new SqlConnection(connString);
conn.Open();
using (SqlCommand cmd = new SqlCommand())
{
cmd.Conn = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO Student(Student_Name,Year) Values (@name,@year)";
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@year", year);
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
}