Vicomi
- Back to Home »
- Stand Alone Application
public class Connection
{
public static string connectionString
{
get { return "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=innosoftPOS;Data Source=Lakshika-PC\\SQLEXPRESS"; }
}
}
---------------------------------------------------------------------------------------------------------
public void insertCustomer(string name, string house, string street, string city, string tel1, string tel2, int creditLimit, int currentCredit)
{
SqlConnection conn = new SqlConnection(Connection.connectionString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "insert into Customer values ('"+name+"','"+house+"','"+street+"','"+city+"','"+tel1+"','"+tel2+"',"+creditLimit+","+currentCredit+");";
cmd.ExecuteNonQuery();
conn.Close();
}
public void deleteCustomer(string name)
{
SqlConnection conn = new SqlConnection(Connection.connectionString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "delete from Customer where name='"+name+"';";
cmd.ExecuteNonQuery();
conn.Close();
}
public void updateCustomer(string name, string house, string street, string city, string tel1, string tel2, int creditLimit, int currentCredit)
{
SqlConnection conn = new SqlConnection(Connection.connectionString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "update Customer set house='"+name+"',street='"+street+"',city='"+city+"',telephone1='"+tel1+"',telephone2='"+tel2+"',creditLimit="+creditLimit+", currentCredit="+currentCredit+" where name='"+name+"';";
cmd.ExecuteNonQuery();
conn.Close();
}
---------------------------------------------------------------------------------------------------------
Calling to DeleteCustomer Fuction
------------------------------------------
private void button2_Click(object sender, EventArgs e)
{
string name = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString();
DbAccess dba = new DbAccess();
dba.deleteCustomer(name);
}
private void button3_Click(object sender, EventArgs e)
{
textBox16.Text = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString();
textBox15.Text = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].Value.ToString();
textBox14.Text = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[2].Value.ToString();
textBox13.Text = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[3].Value.ToString();
textBox12.Text = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[4].Value.ToString();
textBox11.Text = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[5].Value.ToString();
textBox10.Text = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[6].Value.ToString();
textBox9.Text = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[7].Value.ToString();
}
----------------------------------------------------------------------------------------