So my program works as it should. When I click the save button everything is saved to the database. However when I click the save button a second time it fails to work.**Index was outside the bounds of the array.** is the error in private void btnTest\_click on line string Ullage = splitstring[2];

```
  private void btnSave_Click(object sender, EventArgs e)
    {
        OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\2014-06-26 TEK687 Config Tool\TEK687 Config Tool\bin\Debug\Results.mdb");

        string SqlString = "insert into Table1  (PassOrFail,DateTested,TekNum,BatchNum,WeekNum,Serial,FirmwareVer,HardwareVer,TestPC,SettingsTest,Deleted,Ullage,SRC,Vbatt,Tamb,Ullage2,SRC2,Vbatt2,Tamb2) Values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

        using (OleDbCommand cmd = new OleDbCommand(SqlString, conn))
        {
            cmd.CommandType = CommandType.Text;

            cmd.Parameters.AddWithValue("PassOrFail", txtPassFail.Text);
            cmd.Parameters.AddWithValue("DateTested", txtDateTested.Text);
            cmd.Parameters.AddWithValue("TekNum", txtTekPartNo.Text);
            cmd.Parameters.AddWithValue("BatchNum", txtBatchNumber.Text);
            cmd.Parameters.AddWithValue("WeekNum", txtWeekYearNo.Text);
            cmd.Parameters.AddWithValue("Serial", txtSerialNumber.Text);
            cmd.Parameters.AddWithValue("FirmwareVer", txtFirmwareVer.Text);
            cmd.Parameters.AddWithValue("HardwareVer", txtHardwareVer.Text);
            cmd.Parameters.AddWithValue("TestPC", txtTestPC.Text);
            cmd.Parameters.AddWithValue("SettingsTest", cboSettingsProfiles.SelectedIndex);
            cmd.Parameters.AddWithValue("Deleted", txtDeleted.Text);
            cmd.Parameters.AddWithValue("Ullage", txtUllage1.Text);
            cmd.Parameters.AddWithValue("SRC", txtSRC1.Text);
            cmd.Parameters.AddWithValue("Vbatt", txtVbatt1.Text);
            cmd.Parameters.AddWithValue("Tamb", txtTamb1.Text);
            cmd.Parameters.AddWithValue("Ullage2", txtUllage2.Text);
            cmd.Parameters.AddWithValue("SRC2", txtSRC2.Text);
            cmd.Parameters.AddWithValue("Vbatt2", txtVbatt2.Text);
            cmd.Parameters.AddWithValue("Tamb2", txtTamb2.Text);

            conn.Open();
            cmd.ExecuteNonQuery();
            MessageBox.Show("Data stored successfully");
        }

        ClearTextBoxes(this);
    }

```

Here is the code to add values to database error is at **string Ullage = splitstring[2];**

```
 private void btnTest_Click(object sender, EventArgs e)
    {
        Cancel = false;
        if (DiscoverDevice(false) == false)
        {
            MessageBox.Show("Error, device is not responding");
            return;
        }

        string servo = "";
        MyModemSerialInterfaceLayer.WriteTextAndWaitForResponse("TL,S," + txtToolID.Text + ",30,\r\n", "\r\n", 4, ref servo, 500);

        string test = "";
        MyModemSerialInterfaceLayer.WriteTextAndWaitForResponse("TL,T," + txtToolID.Text + "\r\n", "\r\n", 4, ref test, 500);

        string[] splitstring = test.Split(',');
        **string Ullage = splitstring[2];**
        string SRC = splitstring[3];
        string RSSI = splitstring[4];
        string AlarmStatus = splitstring[5];
        string RateofChange = splitstring[6];
        string Tamb = splitstring[7];
        string Vbatt = splitstring[8];

        Ullage = Ullage.Replace("u:", "");
        Tamb = Tamb.Replace("t:", "");
        Vbatt = Vbatt.Replace("v:", "");
        int Ull = Convert.ToInt32(Ullage);
        int src = Convert.ToInt32(SRC);
        int BV = Convert.ToInt32(Vbatt);
        int temp = Convert.ToInt32(Tamb);

        StringBuilder sb = new StringBuilder();
        sb.Append(Ull);
        txtUllage1.Text += sb.ToString();
        StringBuilder sc = new StringBuilder();
        sc.Append(src);
        txtSRC1.Text += sc.ToString();
        StringBuilder sd = new StringBuilder();
        sd.Append(BV);
        txtVbatt1.Text += sd.ToString();
        StringBuilder se = new StringBuilder();
        se.Append(temp);
        txtTamb1.Text += se.ToString();
        StringBuilder sm = new StringBuilder();

        if ((Ull < 11) || (Ull > 13) || (src < 9) || (BV < 29))
        {
            txtPassFail.Text += "12cm FAIL";
              txtResultsReading.Font = new Font(txtResultsReading.Font, FontStyle.Bold);
            StringBuilder th = new StringBuilder();
               th.Append("12cm FAIL");
              txtResultsReading.Text += th.ToString();
        }

        string servoTwo = "";
        MyModemSerialInterfaceLayer.WriteTextAndWaitForResponse("TL,S," + txtToolID.Text + ",31,\r\n", "\r\n", 4, ref servoTwo, 500);
        string tests = "";
        MyModemSerialInterfaceLayer.WriteTextAndWaitForResponse("TL,T," + txtToolID.Text + "\r\n", "\r\n", 4, ref tests, 500);

        string[] splitstrings = tests.Split(',');
        string Ullage2 = splitstrings[2];
        string SRC2 = splitstrings[3];
        string RSSI2 = splitstrings[4];
        string AlarmStatus2 = splitstrings[5];
        string RateofChange2 = splitstrings[6];
        string Tamb2 = splitstrings[7];
        string Vbatt2 = splitstrings[8];

        Ullage2 = Ullage2.Replace("u:", "");
        Tamb2 = Tamb2.Replace("t:", "");
        Vbatt2 = Vbatt2.Replace("v:", "");
        int Ull2 = Convert.ToInt32(Ullage2);
        int src2 = Convert.ToInt32(SRC2);
        int BV2 = Convert.ToInt32(Vbatt2);
        int temp2 = Convert.ToInt32(Tamb2);

        StringBuilder sf = new StringBuilder();
        sf.Append(Ull2);
        txtUllage2.Text += sf.ToString();
        StringBuilder sg = new StringBuilder();
        sg.Append(src2);
        txtSRC2.Text += sg.ToString();
        StringBuilder sh = new StringBuilder();
        sh.Append(BV2);
        txtVbatt2.Text += sh.ToString();
        StringBuilder si = new StringBuilder();
        si.Append(temp2);
        txtTamb2.Text += si.ToString();

        txtDateTested.Text = DateTime.Now.ToString();
        txtTestPC.Text = System.Environment.UserName;
        //boSettingsProfiles.Text= Settings.SettingsFile;
        txtDeleted.Text = "CURRENT";

        if ((Ull < 11) || (Ull > 13) || (src < 9) || (BV < 29))
        {

            txtPassFail.Text += "  3M FAIL";
            txtResultsReading.Font = new Font(txtResultsReading.Font, FontStyle.Bold);
            StringBuilder tg = new StringBuilder();
            tg.Append(Environment.NewLine);
            tg.Append("3M FAIL");
            txtResultsReading.Text += tg.ToString();
        }
        else if ((Ull >= 11) && (Ull <= 13) && (src == 9) && (BV >= 29) &&
            (Ull2 >= 11) && (Ull2 <= 13) && (src2 == 9) && (BV2 >= 29))
        {
            txtPassFail.Text += "PASS";
            txtResultsReading.Font = new Font(txtResultsReading.Font, FontStyle.Bold);
            txtResultsReading.Text += "PASS";
        }
        ReleaseDevice();//release the config tool after config is completed
    }
}

```