1 / 6

Simple MS Access operations

Simple MS Access operations. Monday Nov 14, 2005. Sample Application. Step One: create the database. 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";

nishi
Download Presentation

Simple MS Access operations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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); }

More Related