i'm sorry. i wouldn't post this if i weren't out of ideas. i've tried everything in the forums, but to no avail.
so i have 2 tables. both are empty at the beginning. the first table is kind of like a customer masterlist where the user creates a new customer profile. here is the code:
con.Open();
System.Data.SqlClient.SqlCommandBuilder cb;
System.Data.SqlClient.SqlCommandBuilder readingcb;
cb = new System.Data.SqlClient.SqlCommandBuilder(da);
readingcb = new System.Data.SqlClient.SqlCommandBuilder(readingda);
DataRow dRow = custMaster.Tables["custMaster"].NewRow();
DataRow readingdRow = reading.Tables["reading"].NewRow();
dRow[1] = a_newCust.Text;
readingdRow[9] = a_newCust.Text;
dRow[2] = b_newCust.Text;
readingdRow[10] = b_newCust.Text;
dRow[3] = c_newCust.Text;
readingdRow[11] = c_newCust.Text;
dRow[4] = d_newCust.Text;
readingdRow[0] = d_newCust.Text;
dRow[5] = e_newCust.Text.ToString();
readingdRow[2] = e_newCust.Text.ToString();
dRow[6] = f_newCust.Text;
readingdRow[1] = f_newCust.Text;
dRow[7] = g_newCust.Text.ToString();
if (radioButton1.Checked == true)
{
dRow[8] = radioButton1.Text;
readingdRow[3] = radioButton1.Text;
}
else if (radioButton2.Checked == true)
{
dRow[8] = radioButton2.Text;
readingdRow[3] = radioButton2.Text;
}
dRow[9] = "Active";
readingdRow[12] = "Active";
readingdRow[4] = 0;
readingdRow[5] = 0;
custMaster.Tables["custMaster"].Rows.Add(dRow);
reading.Tables["reading"].Rows.Add(readingdRow);
MaxRows = MaxRows + 1;
readingMaxRows = readingMaxRows + 1;
inc = MaxRows - 1;
readinginc = readingMaxRows - 1;
this.da.Update(custMaster, "custMaster");
this.readingda.Update(reading, "reading");
da.Fill(masterDataSet3.custMaster);
readingda.Fill(streetDataSet.reading);
masterfileGrid.Invalidate();
readingGrid.Invalidate();
masterfileGrid.Refresh();
readingGrid.Refresh();
MessageBox.Show("Customer succesfully added!");
con.Close();
when this part completes, my program will create a new record in the "custMaster" table, and also a new record in the "reading" table (but this record still has some null fields). when the user goes to the "reading" table, he sees the new record, and then updates that record by adding some column values (thereby filling in the null fields). here is the code:
con.Open();
System.Data.SqlClient.SqlCommandBuilder readingup;
System.Data.SqlClient.SqlCommandBuilder custpayadd;
readingup = new System.Data.SqlClient.SqlCommandBuilder(readingda);
custpayadd = new System.Data.SqlClient.SqlCommandBuilder(custpayda);
int test = int.Parse(f_reading.Text);
int prev = int.Parse(readingNinBox.Text);
DataRow readingdRow = reading.Tables["reading"].Rows[test-1];
readingdRow[4] = prev;
readingdRow[5] = int.Parse(d_reading.Text);
readingdRow[13] = e_reading.Value.ToShortDateString();
readingdRow[6] = int.Parse(d_reading.Text) - prev;
if (g_reading.Text == "Residential")
{
DataRow resSearchdRow = water.Tables["water"].Rows[int.Parse(d_reading.Text) - prev];
readingdRow[7] = resSearchdRow[2];
}
else
{
DataRow commSearchdRow = commWater.Tables["commWater"].Rows[int.Parse(d_reading.Text) - prev];
readingdRow[7] = commSearchdRow[2];
}
this.readingda.Update(reading, "reading"); //>>>>>>>>>>this part is where i get the concurrency error.
readingda.Fill(streetDataSet.reading);
readingGrid.Invalidate();
readingGrid.Refresh();
//elsewhere:
masterDataSet reading;
System.Data.SqlClient.SqlDataAdapter readingda;
int readingMaxRows = 0;
int readinginc = 0;
this.readingTableAdapter.Fill(this.streetDataSet.reading);
reading = new masterDataSet();
string readingsql = "SELECT * From reading";
readingda = new System.Data.SqlClient.SqlDataAdapter(readingsql, con);
readingda.Fill(reading, "reading");
readingMaxRows = reading.Tables["reading"].Rows.Count;
readingda.Update(reading, "reading");
i don't understand why i get this, since i use the same lines of updating codes in my other forms but they work well. any help would be greatly appreciated. thanks.
Some additional information: i only get the error the first time a record is added to the "reading" table. when i close and reopen my program, i can update the record fine.