Oh Lord, I have never worked on a project that is as frustrating as this.
When one complicated problem is solved, just when I think I am done, another problem comes up.
A few days ago, Dharmendr was kind enough to help me solve this problem on this link (pages 2 and 3).
http://www.aspforums.net/Threads/107087/Error-SystemDataDataRowView-does-not-contain-a-property-with-the-name-MarineRegNo-using-C-in-ASPNet/?p=2
Right now, what is happening is that when I enter an account number and no record exists for that account number, I can enter records, click submit and everything is saved just fine.
The issue is if I enter an account number and it pulls up the existing records, if I just make one change and click submit, I get the following error:
Index was outside the bounds of the array.
That error points to this block of code in the markup:
Markup:
<%foreach (System.Data.DataRow row in dtAirInfoTable.Rows)
{%>
<tr>
<td>
<span class="form-control" style="width: 493px; color: #0093B2;font-weight: bold;"> <%=row.ItemArray[1].ToString()%></span>
</td>
<td align="center">
<span class="form-control txtPayerret" style="width: 400px;color: #0093B2; font-weight: bold;"><%=row.ItemArray[2].ToString()%></span>
</td>
</tr>
<tr>
<td>
<span class="form-control" style="width: 493px; color: #0093B2;font-weight: bold;"> <%=row.ItemArray[3].ToString()%></span>
</td>
<td align="center">
<span class="form-control txtPayerret" style="width: 400px;color: #0093B2; font-weight: bold;"><%=row.ItemArray[4].ToString()%></span>
</td>
</tr>
<% } %>
C#
DataTable regtable = ViewState["CurrTable"] as DataTable;
try
{
conn.Open();
if (regtable != null)
{
foreach (DataRow row in regtable.Rows)
{
string txBoatRegNum = row.ItemArray[1] as string;
string txTaxPayerRet = row.ItemArray[2] as string;
string txVesselRegNum = row.ItemArray[3] as string;
string txVTaxPayerRet = row.ItemArray[4] as string;
//prevent money data types from breaking. If user does not enter value, then enter 0 in its place
//This sub will store Marine and Vessel info to the database.
if (txTaxPayerRet != null & txVTaxPayerRet != null)
{
if (string.IsNullOrEmpty(txTaxPayerRet))
{
txTaxPayerRet = "0";
}
if (string.IsNullOrEmpty(txVTaxPayerRet))
{
txVTaxPayerRet = "0";
}
SqlCommand aircmd = new SqlCommand("sp_saveMarineInfo", conn);
aircmd.CommandType = CommandType.StoredProcedure;
aircmd.Parameters.AddWithValue("@pid", accountnumber.Text);
aircmd.Parameters.AddWithValue("@eID", Request["pageId"]);
aircmd.Parameters.AddWithValue("@txYr", txtTaxYr.Text);
aircmd.Parameters.AddWithValue("@marineRegno", txBoatRegNum);
aircmd.Parameters.AddWithValue("@vesselRegno", txVesselRegNum);
aircmd.Parameters.Add("@txretval", SqlDbType.Money).Value = decimal.Parse(txTaxPayerRet); //convert text back to money
aircmd.Parameters.Add("@vtxretval", SqlDbType.Money).Value = decimal.Parse(txVTaxPayerRet); //convert text back to money
aircmd.ExecuteNonQuery();
}
}
}
These parts are part of the C#
SetInitialRow()
AddNewRowToGrid()
and they can be seen on the line I posted.
I am hoping and praying these will finally fix the issues for this stupid project.
Many, many thanks for all the incredible help here.