Groups | Blog | Home
all groups > dotnet windows forms databinding > september 2005 >

dotnet windows forms databinding : Databinding in VS 2005 Beta 2 on datagridview control


TheOne
9/13/2005 1:34:35 PM
Hi, I am setting up DataSource and DataMember of datagridview control to
some table in dataset. Once I insert new record, I update this information
to database and accept changes. Problem is that since I am generating
primary key for this table in Oracle, my datagridview has different primary
key then the one that is actual in database. I need to refresh datagridview
control now with new data from database. I am having problems doing so. I
would like to remove any bindings from control and set them up again. I need
to do this since I have different data in datagridview and dataset. I am not
sure how to completely clear databindings and create new once.



Thanks,

Sinisa

v-jetan NO[at]SPAM online.microsoft.com (
9/14/2005 12:00:00 AM
Hi Sinisa,

Thanks for your post.

[quoted text, click to view]
database
I am not sure why the primary key in dataset is different from the primary
key in the database, normally, we suggest you use the same primary key in
dataset as in database.

Do you use OLEDbdataAdapter to do the database operation? Do you use data
adapter configuration wizard to gerenate OLEDbdataAdapter? Normally, when
we are using data adapter configuration to generate the code, there is a
"Advanced Option" dialog, which we can check the "Refresh the DataSet"
option. With this option turned on, VS.net will add a Select statement
after Insert and Update command to retrieve identity column value, default
values, and other values calculated by the database.

Below is the command text generated for SqlDataAdapter:
this.sqlInsertCommand1.CommandText ="INSERT INTO jobs(job_desc, min_lvl,
max_lvl) VALUES (@job_desc, @min_lvl, @max_lvl); SELECT job_id, job_desc,
min_lvl, max_lvl FROM jobs WHERE (job_id = @@IDENTITY)";

If you do not use the wizard to generate the Insert command, I think you
have to maually add this additional insert statement.

Addtionally, because @@IDENTITY only returns the last identity value, if we
insert multi-records, we'd better re-select the entire table from DataBase
into the datatable.(That is remove "WHERE (job_id = @@IDENTITY)" from the
select command text abvoe)

Also, because this issue is more ADO.net related than Winform databinding
issue, I suggest you post such issue in ADO.net newsgroup later on, then
you will get more useful reply and help.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
John
9/14/2005 7:20:27 AM
Should that be Scope_Identity()?

[quoted text, click to view]
TheOne
9/14/2005 8:35:45 AM
Hi I am using MS Oracle Driver or Oracle Driver (depending on application).
I am binding dataset with specific table manually in code behind by setting
DataSource and DataMember of datagridview control. After I insert one record
and update Oracle database, there is a trigger on that table that assigns
primary key to the new record. On other side my dataset does not have
correct information since primary key has changed. I need to get new data
from dataset and bind it again with this datagrid. I would like to know what
is the easies way to do so? I hope that I explained little bit more my
problem with this message.

Thanks,

Sinisa



[quoted text, click to view]

v-kevy NO[at]SPAM online.microsoft.com
9/15/2005 7:30:39 AM
Hi Sinisa,

If you're generating the DataAdapter using wizard, you can try to set in
the Advanced Options dialog box, check the Refresh DataSet option. A select
statement will be added after INSERT statement in the generated code.

If you're writing the DataAdapter code yourself, you can add a select
statement manually to the insert command. Here is a document for your
reference. It is specific to SQL server database. I'm not quite familiar
with Oracle SQL statements, but you can change the @@IDENTITY or
SCOPE_IDENTITY() to the oracle version.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconretrievingidentityorautonumbervalues.asp

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
AddThis Social Bookmark Button