Presentation is loading. Please wait.

Presentation is loading. Please wait.

Simple MS Access operations

Similar presentations


Presentation on theme: "Simple MS Access operations"— Presentation transcript:

1 Simple MS Access operations
Monday Nov 14, 2005

2 Sample Application

3 Step One: create the database

4 Connecting to the Database
private void Form1_Load(object sender, System.EventArgs e) { // connect to the existing Access Database string cmd = "Select name,qnty from Table1"; string connect = "provider=Microsoft.JET.OLEDB.4.0; data source = c:\\products.mdb"; myAdapter = new OleDbDataAdapter(cmd, connect); // get the data from the database DataSet mydata = new DataSet(); myAdapter.Fill (mydata, "Table1"); mytable = mydata.Tables[0]; // fill up the comboBox with the rows foreach (DataRow dataRow in mytable.Rows) comboBox1.Items.Add(dataRow["name"]); }

5 Really Simple Query private void btn_quantity_Click(object sender, System.EventArgs e) { // connect again string cmd = "Select name,qnty from Table1"; string connect = "provider=Microsoft.JET.OLEDB.4.0; data source = c:\\products.mdb"; myAdapter = new OleDbDataAdapter(cmd, connect); // get a fresh copy of the database DataSet mydata = new DataSet(); myAdapter.Fill (mydata, "Table1"); mytable = mydata.Tables[0]; // look for the item and show its qnty foreach (DataRow dataRow in mytable.Rows) if (String.Compare(dataRow["name"].ToString(),comboBox1.Text) == 0) MessageBox.Show("There are " + dataRow["qnty"].ToString(), }

6 Really Simple Remove private void btn_Delete_Click(object sender, System.EventArgs e) { // update the database foreach (DataRow dataRow in mytable.Rows) if (String.Compare(dataRow["name"].ToString(),comboBox1.Text) == 0) dataRow.Delete(); } comboBox1.Items.Remove(comboBox1.Text);


Download ppt "Simple MS Access operations"

Similar presentations


Ads by Google