Hi all
I am trying to enter data into textboxes which will then store the data entered into a database. When I debug everything starts but when I click Add, the database stays the same. I think I might be missing something in my code. Any help is appreciated.
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.SqlServerCe;
namespace Acc
{
public partial class New_Customer : Form
{
public SqlCeConnection cn = new SqlCeConnection(@"Data Source = C:\Projects\Acc\Acc\Customers.sdf");
public New_Customer()
{
InitializeComponent();
}
private void New_Customer_Shown(object sender, EventArgs e)
{
try
{
cn.Open();
}
catch (SqlCeException ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.ExitThread();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
// nothing will happen if A/C ref and customer name are empty
if (txtACRef.Text != "" && txtCustomerName.Text != "")
{
btnAdd.Enabled = true;
}
else
{
btnAdd.Enabled = false;
}
}
private void btnAdd_Click_1(object sender, EventArgs e)
{
SqlCeCommand cn = new SqlCeCommand("INSERT INTO tblCustomers (Customer_Ref, Customer_Name) VALUE(@Customer_Ref, @Customer_Name)");
cn.Parameters.AddWithValue("@Customer Ref", txtACRef.Text);
cn.Parameters.AddWithValue("@Customer Name", txtCustomerName.Text);
}
}
}