473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

OdbcCommandBuilder doesn't generates a valid InsertCommand

Elnath
2
im connecting to a DataBase tru ODBC, i need to insert new records (rows) therefore i want the InsertCommand to be generated by my CommbadBuilder. This solution however is aint working, the SelectCommand generate simply ignore all but one of the fields in the source table as a result the InsertCommand generated will only insert the selected field.

Used both "Select *" and the extended select listing all of the 94 fields of the table, both cases return the same SelectCommand that is selecting only the keyfield of the table. I think that if i have my CommandBuilder interprets corretly the query passed it will be able to generate a proper InsertCommand query.

and here is some code:

Expand|Select|Wrap|Line Numbers
  1. OdbcDataAdapter adp = new OdbcDataAdapter("select * from tabTest", ms_cnn);
  2. OdbcCommandBuilder cb = new OdbcCommandBuilder(adp);
  3. adp.Fill(local_ds, "tabTest");
  4.  
ms_cnn hold a valid and open connection so that my connection will not be closed upon the update, as i need to insert many rows. If i browse the DataTable it is correctly filled with values but not after the update (looking from the DB) either im not getting any exception this mean the fields are correctly filled but due to the InsertCommand only the one field selected by the SelectCommand will be inserted into my table. As u see the select statement ask for all the fields on the table and as said listing all of the fields has no result.

Is there any know issue related to the use of CommandBuilder in this case? Ive used for works past and it was correctly selecting the whole records as asked due to the query used.


thanks all,
Oct 5 '07 #1
2 2685
Plater
7,872 Expert 4TB
The description on MSDN does not seem like it it ment to do that?

The OdbcDataAdapter does not automatically generate the SQL statements required to reconcile changes made to a DataSet associated with the data source. However, you can create an OdbcCommandBuilder object that generates SQL statements for single-table updates by setting the SelectCommand property of the OdbcDataAdapter. The OdbcCommandBuilder then generates any additional SQL statements that you do not set.

The relationship between an OdbcDataAdapter and its corresponding OdbcCommandBuilder is always one-to-one. To create this correspondence, you set the OdbcDataAdapter property of the OdbcCommandBuilder object. This causes the OdbcCommandBuilder to register itself as a listener, which produces the output of RowUpdating events that affect the DataSet.

To generate INSERT, UPDATE, or DELETE statements, the OdbcCommandBuilder uses the SelectCommand property to retrieve a required set of metadata. If you change the value of SelectCommand after the metadata has been retrieved, such as after the first update, you should then call the RefreshSchema method to update the metadata.

Note
If the SELECT statement assigned to the SelectCommand property uses aliased column names, the resulting INSERT, UPDATE, and DELETE statements may be inaccurate or fail. If the underlying ODBC driver cannot provide the appropriate base column name for the alias column name (using the SQL_DESC_BASE_COLUMN_NAME value of SQLColAttribute), the alias name could be used in the generated INSERT, UPDATE, and DELETE statements. For example, the Microsoft ODBC Driver for Oracle returns the alias name as the base column name. Therefore, the generated INSERT, UPDATE, and DELETE statements would cause errors.
Oct 5 '07 #2
Elnath
2
The description on MSDN does not seem like it it ment to do that?
from my local MSDN and from how i used it before:

Automatically generates single-table commands that are used to reconcile changes made to a DataSet with the associated data source.
it should generate the InsertCommand query, but if this is not enought why after i pass a selection query listing all the fields (both with * or every single field) it show me a select with only the key field?

this mean he actually read correctly the DataTable of my DB (with * ive not specified a field name) and will lookup that field, so why it will not consider other fields aswell?

due to my line 2 im using a CommandBuilder to generate the SQL statement, im not expecting the adapter to do that for me:

Expand|Select|Wrap|Line Numbers
  1. OdbcDataAdapter adp = new OdbcDataAdapter("select * from tabTest", ms_cnn);
  2. OdbcCommandBuilder cb = new OdbcCommandBuilder(adp);
  3. adp.Fill(local_ds, "tabTest");
  4.  
Oct 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: simtin | last post by:
Hi guys. I'm using a DataSet, a OdbcDataAdapter, beeing constructed by pubDA_URL = new OdbcDataAdapter()( new OdbcCommand("select * from urls where project=" + id, pubDB) );
0
by: ehmy | last post by:
Hello. I find OdbcCommandBuilder can not work properly when prepare command for Sybase ASE Server 12.0. I need to access Sybase ASE Server 12.0, but Oledb provider provided by Sybase can not...
5
by: Darryn Ross | last post by:
Hi, I am running an insert statement into an access database, but i don't want to add information to every column in my table... when i run my insertcommand the following exception is thrown......
1
by: Luboą ©lapák | last post by:
Hi, I need define InsertCommand in SQLDataAdapter, but I don't know how. Please Help me. I don't know the format of InsertCommand. Thanks
2
by: Pete Davis | last post by:
I'm trying to add a new record to an access table. I'm using Odbc because I'm deploying it on a web site using MySql. Performance isn't an issue at all. Anyway, I've never done Odbc and I'm not...
3
by: Jon S via DotNetMonster.com | last post by:
Hi all, I'm having a problem updating a simple change I've made to a Access 2000 table through databinding. The error I get is : An unhandled exception of type...
1
by: zoneal | last post by:
I retrieved the following function from VB.NET help and added a few statements for updating the datasource. But, it does not actually commence the InsertCommand property of the DataAdapter in order...
3
by: Rich | last post by:
What is the diffeence bewtween a dataAdapter.InsertCommand and dataAdapter.SelectCommand (and dataAdapter.UpdateCommand for that matter)? Dim da As SqlDataAdapter conn.Open da.SelectCommand =...
2
by: Roget | last post by:
Using a DetailsView and SQLDataSource controls I am passing three values through an InsertCommand into a SQL Server database. <asp:SqlDataSource ID="AP_ListData" runat="server"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.