Hi Guys...
I seem to be having an issue when trying to create a new row in a Dataset. Below is the following Connection Details to the Access DB.
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
cashCustom.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Orders.mdb";
cashCustomerDS = new DataSet();
cashcTable = new DataTable();
cashCustomerDS.Tables.Add(cashcTable);
cashCustom.Open();
//cashCustom.Close();
string sql = "SELECT * FROM cashCustomers";
cashDA = new System.Data.OleDb.OleDbDataAdapter(sql, cashCustom);
cashDA.Fill(cashcTable);
foreach (DataRow myRow in cashcTable.Rows)
{
listView1.Items.Add(myRow[0].ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add(myRow[1].ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add(myRow[4].ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add(myRow[2].ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add(myRow[3].ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add(myRow[5].ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add(myRow[6].ToString());
}
As you can see from above it connects to the database and Selects all from cashCustomers and lists the items out in a list view.
Now... Here is the code for the Save button.
private void button1_Click(object sender, EventArgs e)
{
if (cashCustomerDS != null && cashCustomerDS.Tables.Count > 0)
{
**DataRow dRow = cashCustomerDS.Tables["orders.cashCustomers"].NewRow();**
dRow[1] = txtAccRef.Text;
dRow[2] = txtName.Text;
dRow[3] = txtAddr1.Text;
dRow[4] = txtAddr2.Text;
dRow[5] = txtTown.Text;
dRow[6] = txtCounty.Text;
dRow[7] = txtTown.Text;
cashCustomerDS.Tables["cashCustomers"].Rows.Add(dRow);
cashDA.Update(cashCustomerDS, "cashCustomers");
MessageBox.Show("Cash Account Added");
}
Data should be pulled from the Linked txt boxes placed on a new row in the dataset and then using the dataAdapter the cashCustomers table should be updated.
Once I input new details into said text boxes the syste bugs out on the high-lighted row above stating the following:
NullReferenceException was Unhandled
Object reference not set to an instance of an object
I'm guessing its because the system believes the Dataset is blank?
any helkp would be great. Thanks in advance.
Mark.