rowlandsfc
Active member
Hi i have a basic application that is used to display customer information from a sql database, i am using a datagridview to display the information, i also have a form that has texboxdes on it to enter customer information for adding to that database which currently works. what i need to do now is id like to be able to search for a specific customer id(custid) in the table and get their information and fill in the same textboxes so that i can edit their info if needed and then save it back to the database.
any help would be appreciated
Adding customer info to database:
namespace NewSQLiteCardiff
{
public partial class AddCustomer : Form
{
public AddCustomer()
{
InitializeComponent();
}
SQLiteConnection conn;
private void AddCustomer_Load(object sender, EventArgs e)
{
// connects to the customers database
try
{
conn = new SQLiteConnection();
conn.ConnectionString = dbConnection.source;
conn.Open();
}
catch (Exception ex)
{
conn.ConnectionString = dbConnection.source;
conn.Close();
MessageBox.Show(ex.Message);
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
using (SQLiteCommand cmd = conn.CreateCommand())
{
// adds customers details to the database
cmd.CommandText = @"INSERT INTO customer (title, " + "firstname, " + "lastname, " + "dob, " + "nicode, " + "email, " + "password, " + "allowance) VALUES (@setTitle, @setFirstname, @setLastname, @setDOB, @setNICode, @setEmail, @setPassword, @setAllowance)";
cmd.Parameters.AddWithValue("setTitle", cb_title.Text);
cmd.Parameters.AddWithValue("setFirstname", txtFirst_Name.Text);
cmd.Parameters.AddWithValue("setLastname", txtSurname.Text);
cmd.Parameters.AddWithValue("setDOB", dtp_DOB.Text);
cmd.Parameters.AddWithValue("setNICode", txtNI_Code.Text);
cmd.Parameters.AddWithValue("setEmail", txtEmail.Text);
cmd.Parameters.AddWithValue("setPassword", txtPassword.Text);
cmd.Parameters.AddWithValue("setAllowance", txtAllowance.Text);
int recordsChanged = cmd.ExecuteNonQuery();
MessageBox.Show("Customer Added");
conn.Close();
Customers customers = new Customers();
customers.Show();
this.Hide();
}
}
// cancel button to cancel adding new customer and returnsto the customers tables
private void btnCancel_Click(object sender, EventArgs e)
{
Customers customers = new Customers();
customers.Show();
this.Hide();
}
}
}
any help would be appreciated