Object reference not set to an instance of an object. Please Help!

  • Thread starter Thread starter Khalid kk
  • Start date Start date
K

Khalid kk

Guest
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;
using System.Data.SqlClient;
using System.IO;
using System.Configuration;

namespace Finance_and_Cost_Controlling_System
{
public partial class Customer : Form
{
static string constring = ConfigurationManager.ConnectionStrings["Finance_and_Cost_Controlling_System.Properties.Settings.Setting"].ConnectionString;
SqlConnection con = new SqlConnection(constring);
//SqlConnection con = new SqlConnection("Data Source = KHALIDKK; initial Catalog = SIGBL; integrated security = false; User Id = sa; Password= 02136660711...; Timeout = 45; MultipleActiveResultSets=True;");
SqlCommand command;

public Customer()
{
InitializeComponent();
}

private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{
if (panel1.Visible == false)
{

bunifuTransition1.ShowSync(panel1);
panel1.Visible = true;
panel1.Width = 1184;
button3.Enabled = true;
}
else
{

bunifuTransition1.ShowSync(panel1);
panel1.Visible = false;
panel1.Width = 10;
}
}





private void button3_Click(object sender, EventArgs e)
{
panel1.Hide();
}

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Inserted");
try
{
if (con.State != ConnectionState.Open)
con.Open();


string conn = "INSERT INTO Customer (Firstname,Lastname,Email,Company,Phone,Mobile,Other,Website,Fax,Street1,Street2,Country,City,ProvinceState,Notes,Postcode)VALUES('" + textBox1.Text + "','" + textBox2.Text + "', '" + textBox3.Text + "', '" + textBox4.Text + "', '" + textBox5.Text + "', '" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + textBox10.Text + "','" + textBox11.Text + "', '" + comboBox1.SelectedItem.ToString() + "', '" + textBox12.Text + "', '" + comboBox2.SelectedItem.ToString() + "','" + richTextBox1.Text + "', '" + textBox13.Text + "')";
command = new SqlCommand(conn, con);

int x = command.ExecuteNonQuery();
con.Close();
MessageBox.Show(x.ToString() + "record(s) saved.");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}




1454251.png

Continue reading...
 
Back
Top