Generated code for DataGridView and Update

G

Guest

Hi,

I have a DataGridView that displays data from one table from database. I
didn’t implement any my code, I just used wizard to do all the work with
DatagridView populating.

Visual Studio generated strong typed dataset and binding. And here is my
problem.
I try to update the database with the new (changes) values from DataGridView:

Settings generated by Visual Studio:
dataGridView1.DataSource = tblMyTableBindingSource;

dataSetLKS.DataSetName = “DataSetLKSâ€

tblMyTableBindingSource.DataMember = “tblMyTableâ€;
tblMyTableBindingSource.DataSource = dataSetLKS;


private void button_Cllick(…)
{
this.tblMyTableAdapter.Update(this.MyDataSetName.Tables[0]);
}

I get error message “Update requires a valid UpdateCommand when passed
DataRow collection with modified rows.â€

The one of auto generated Update methods is:

Public virtual int Update(DataSetLKS.tbl_StatusDataTable dataTable)
{
….
}

How should I correct the Update command?

Thanks,

Lubomir
 
R

RobinS

Does your table have a primary key, and is it included in the data
displayed?

Robin S.
 
G

Guest

Yes, Ihave a primary key and I am displaying it.

Can it be a bug in generated code?
when I added the bindingSource control, set up its property and set the
datasource from grid to this control everything works fine.

But I can not get away with autogenerated code.

Thanks,

Lubomir



RobinS said:
Does your table have a primary key, and is it included in the data
displayed?

Robin S.
-----------------------
Lubomir said:
Hi,

I have a DataGridView that displays data from one table from database. I
didn't implement any my code, I just used wizard to do all the work with
DatagridView populating.

Visual Studio generated strong typed dataset and binding. And here is my
problem.
I try to update the database with the new (changes) values from
DataGridView:

Settings generated by Visual Studio:
dataGridView1.DataSource = tblMyTableBindingSource;

dataSetLKS.DataSetName = "DataSetLKS"

tblMyTableBindingSource.DataMember = "tblMyTable";
tblMyTableBindingSource.DataSource = dataSetLKS;


private void button_Cllick(.)
{
this.tblMyTableAdapter.Update(this.MyDataSetName.Tables[0]);
}

I get error message "Update requires a valid UpdateCommand when passed
DataRow collection with modified rows."

The one of auto generated Update methods is:

Public virtual int Update(DataSetLKS.tbl_StatusDataTable dataTable)
{
..
}

How should I correct the Update command?

Thanks,

Lubomir
 
R

RobinS

What is the error message that you are getting? The Update Command doesn't
exist? Is it in the generated code? If you look at the properties in your
strongly typed dataset, does the Update SQL look right?

You're not joining two tables together, are you?

Robin S.
-------------------------------
Lubomir said:
Yes, Ihave a primary key and I am displaying it.

Can it be a bug in generated code?
when I added the bindingSource control, set up its property and set the
datasource from grid to this control everything works fine.

But I can not get away with autogenerated code.

Thanks,

Lubomir



RobinS said:
Does your table have a primary key, and is it included in the data
displayed?

Robin S.
-----------------------
Lubomir said:
Hi,

I have a DataGridView that displays data from one table from database.
I
didn't implement any my code, I just used wizard to do all the work
with
DatagridView populating.

Visual Studio generated strong typed dataset and binding. And here is
my
problem.
I try to update the database with the new (changes) values from
DataGridView:

Settings generated by Visual Studio:
dataGridView1.DataSource = tblMyTableBindingSource;

dataSetLKS.DataSetName = "DataSetLKS"

tblMyTableBindingSource.DataMember = "tblMyTable";
tblMyTableBindingSource.DataSource = dataSetLKS;


private void button_Cllick(.)
{
this.tblMyTableAdapter.Update(this.MyDataSetName.Tables[0]);
}

I get error message "Update requires a valid UpdateCommand when passed
DataRow collection with modified rows."

The one of auto generated Update methods is:

Public virtual int Update(DataSetLKS.tbl_StatusDataTable dataTable)
{
..
}

How should I correct the Update command?

Thanks,

Lubomir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top