Hello, im trying to insert data to sql server and its not working so well even the code not show any error message or errors on compile. when i check the database......hes empty. Please look at the code for sulotion:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True;");
try
{
SqlCommand cmd = new SqlCommand("INSERT INTO customers(firstName,lastName,address,city) VALUES ('wee','weeee','dfddd', 'weee')", conn);
conn.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Connection Succeful");
}
catch (SqlException ex)
{
MessageBox.Show("There is an Error" + ex);
}
finally
{
conn.Close();
MessageBox.Show("Connection Closed");
}
}
}
}