i am working on a simple database project in c sharp and ms sql sever 2008 but im having an error upon compiling the program its poping up this message:
The type initializer for 'StudentsInformationSystem.DB_conection' threw an exception
My code:
namespace StudentsInformationSystem
{
class DB_Access
{
private SqlConnection conn;
public DB_Access()
{
conn = DB_conection.GetConnection(); //this is where i am getting the error on this line of code
}
public void add_student(string regNo,string fname, string lname, string phoneNo)
{
if (conn.State.ToString() == "closed")
{
conn.Open();
}
SqlCommand newCmd = conn.CreateCommand();
newCmd.Connection = conn;
newCmd.CommandType = CommandType.Text;
newCmd.CommandText = "insert into student values('" + regNo + "','" + fname + "','" + lname + "','" + phoneNo + "')";
newCmd.ExecuteNonQuery();
}
}
}