all groups > dotnet odbc.net > march 2006 >
You're in the

dotnet odbc.net

group:

odbccommandbuilder


odbccommandbuilder Anders R
3/9/2006 8:19:41 PM
dotnet odbc.net:
Hi,

I have a small problem with "odbccommandbuilder".

I get an exception exception = {"ERROR [07002] [Microsoft][ODBC Microsoft
Access Driver]COUNT field incorrect"}

--- START CODE ---

public void WriteDataToDatabase(DataSet ds)
{

/* --- SQL INSERT INTO Statement ---
* INSERT INTO "table_name" ("column1", "column2", ...)
* VALUES ("value1", "value2", ...)
*/

try
{
string mySelectQuery = "INSERT INTO Info (Name, Age) VALUES (?, ?)";
OdbcDataAdapter da = new OdbcDataAdapter();
da.InsertCommand = new OdbcCommand (mySelectQuery, conn);
da.SelectCommand = new OdbcCommand("select * from Info", conn);
OdbcCommandBuilder cb = new OdbcCommandBuilder(da);

//If I enables this code below, all works fine!

//da.InsertCommand = conn.CreateCommand();

//da.InsertCommand.CommandText = "insert into Info " +
// "(Name, Age) " +
// "values " +
// "(?, ?)";

//da.InsertCommand.Parameters.Add("Name", OdbcType.Char, 0, "Name");
//da.InsertCommand.Parameters.Add("Age", OdbcType.Char, 0, "Age");

//Without the OdbcCommandBuilder this line would fail, It fails
anyway :)
da.Update(ds, "Info");

}

catch (Exception exception)
{
throw exception;
}
}


--- END CODE ---

Can anyone help??

Best Regards
/Anders

Re: odbccommandbuilder Paul Clement
3/10/2006 8:01:20 AM
[quoted text, click to view]

¤ Hi,
¤
¤ I have a small problem with "odbccommandbuilder".
¤
¤ I get an exception exception = {"ERROR [07002] [Microsoft][ODBC Microsoft
¤ Access Driver]COUNT field incorrect"}
¤

¤ string mySelectQuery = "INSERT INTO Info (Name, Age) VALUES (?, ?)";

¤
¤ Can anyone help??

Name is a reserved word. In order to use it in a SQL statement you must enclose it within brackets.


Paul
~~~~
Re: odbccommandbuilder Anders R
3/14/2006 12:00:00 AM
Hi Paul,

Thanks fo your answer.

I have tried with the barckets, but without any success. I use C# btw.
Do you or anyone else has any other ideas?

Could it be a bug in .NET framwork 2.0?

I will go with my working alternative for now, but it would be nice to have
the commandBuilder working...

Best regards
Anders

"Paul Clement" <UseAdddressAtEndofMessage@swspectrum.com> skrev i
meddelandet news:3i1312p4jdck54op3qbqr3r181e77f5snl@4ax.com...
[quoted text, click to view]

Re: odbccommandbuilder Paul Clement
3/15/2006 8:24:49 AM
[quoted text, click to view]

¤ Hi Paul,
¤
¤ Thanks fo your answer.
¤
¤ I have tried with the barckets, but without any success. I use C# btw.
¤ Do you or anyone else has any other ideas?
¤
¤ Could it be a bug in .NET framwork 2.0?
¤
¤ I will go with my working alternative for now, but it would be nice to have
¤ the commandBuilder working...
¤
¤ Best regards
¤ Anders

I typically recommend using the Jet OLEDB provider instead of the MS Access ODBC driver.
Unfortunately I don't recognize the error.

Can you identify the line on which the error occurs?


Paul
~~~~
Re: odbccommandbuilder Anders R
4/7/2006 5:00:22 PM
Hi Paul

Here is the line that doesn't work...

OdbcCommandBuilder cb = new OdbcCommandBuilder(da);

I have gone with the other approach where i'll do the insert command
manually...

Regards
Anders

"Paul Clement" <UseAdddressAtEndofMessage@swspectrum.com> skrev i
meddelandet news:pq8g121un4t75u0hcpdv3qjce4e74f4can@4ax.com...
[quoted text, click to view]

AddThis Social Bookmark Button