Chidiebere Mgbemena

Chidiebere Mgbemena

  • NA
  • 179
  • 14.4k

ERROR WHEN WRITING C# CODES TO ADD BUTTON ON MY CONTACT FORM

Nov 12 2018 5:25 AM

using Contacts.contactClasses;

using System;

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;

namespace Contacts

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

contactClass c = new contactClass();

private void textBox1_TextChanged(object sender, EventArgs e)

{

}

private void Form1_Load(object sender, EventArgs e)

{

}

private void btnAdd_Click(object sender, EventArgs e)

{

//Get the value from the input fields

c.FirstName = txtboxFirstName.Text;

c.LastName = txtboxLastName.Text;

c.ContactNo = txtBoxContactNumber.Text;

c.Address = txtBoxAddress.Text;

c.Gender = cmbGender.Text;

//Inserting data into database using the method we created in previous episode

bool success = c.Insert(c);

if(success==true)

{

//Successfully inserted

MessageBox.Show("New Contact Successfully Inserted");

}

else

{

//Failed to add contact

MessageBox.Show("Failed to add Contact. Try Again");

}

}

}

}


I am having error pointing at contactClass c = new contactClass 
 
 when i run the programme. here is th error
 
"An unhandled exception of type 'System.TypeInitializationException' occurred in Contacts.exe
Additional information: The type initializer for 'Contacts.contactClasses.contactClass' threw an exception".
 
Please help!!! 
 
  
 

Answers (4)