I have a problem here, I have a query to the database, where I choose only one table, loads it into the dataSet and fill the DataGridView.
comm = new SqlCommand("Select * from measurement where me_user=@id order by me_date DESC", conn);
comm.Parameters.AddWithValue("@id", this.uId);
daPomiar = new SqlDataAdapter();
daPomiar.SelectCommand = comm;
daPomiar.Fill(dsPomiar, "Pomiary");
dataGridView2.DataSource = dsPomiar;
dataGridView2.DataMember = "Pomiary";
Adds to this
SqlCommandBuilder cmdBldr = new SqlCommandBuilder(daPomiar);
However, when I try to update the data using BindingNavigotor:
private void toolStripButton1_Click(object sender, EventArgs e)
{
SqlCommandBuilder cmdBldr = new SqlCommandBuilder(daPomiar);
daPomiar.Update(dsPomiar, "Pomiary");
}
then sometimes it works and sometimes it gives me an error:
Dynamic SQL generation is not supported against multiple base tables.
My question is, why it happens. I am working on one table, so I can use SqlCommandBuilder (I think). Well, the error is not regular - sometimes error appears and sometimes it works - the data is updated in the table.
Your query tells me that you are selecting data from the measurement
table. I believe you are trying to update to the Pomiary
table. Although you are providing a DataMember and such, I believe the best practice is to keep your DataMember and table names all the same.
Also, make sure your connection is open, I don't see anything on that, might be left out.
string tableName = "measurement";
comm = new SqlCommand("Select * from measurement where me_user=@id order by me_date DESC", conn);
comm.Parameters.AddWithValue("@id", this.uId); //not sure what this does
daPomiar = new SqlDataAdapter(comm, tableName);
daPomiar.Fill(dsPomiar, tableName);
dataGridView2.DataSource = dsPomiar;
toolstrip:
private void toolStripButton1_Click(object sender, EventArgs e)
{
SqlCommandBuilder cmdBldr = new SqlCommandBuilder(daPomiar);
daPomiar.Update(dsPomiar, tablename);
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments