[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Anders R

3/9/2006 7:20:00 PM

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


4 Answers

Paul Clement

3/10/2006 2:01:00 PM

0

On Thu, 9 Mar 2006 20:19:41 +0100, "Anders R" <abc@cnn.com> wrote:

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

&#164; string mySelectQuery = "INSERT INTO Info (Name, Age) VALUES (?, ?)";

&#164;
&#164; Can anyone help??

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


Paul
~~~~
Microsoft MVP (Visual Basic)

Anders R

3/14/2006 10:42:00 AM

0

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...
> On Thu, 9 Mar 2006 20:19:41 +0100, "Anders R" <abc@cnn.com> wrote:
>
> &#164; Hi,
> &#164;
> &#164; I have a small problem with "odbccommandbuilder".
> &#164;
> &#164; I get an exception exception = {"ERROR [07002] [Microsoft][ODBC
> Microsoft
> &#164; Access Driver]COUNT field incorrect"}
> &#164;
>
> &#164; string mySelectQuery = "INSERT INTO Info (Name, Age) VALUES (?,
> ?)";
>
> &#164;
> &#164; Can anyone help??
>
> Name is a reserved word. In order to use it in a SQL statement you must
> enclose it within brackets.
>
>
> Paul
> ~~~~
> Microsoft MVP (Visual Basic)


Paul Clement

3/15/2006 2:25:00 PM

0

On Tue, 14 Mar 2006 11:42:03 +0100, "Anders R" <abc@cnn.com> wrote:

&#164; Hi Paul,
&#164;
&#164; Thanks fo your answer.
&#164;
&#164; I have tried with the barckets, but without any success. I use C# btw.
&#164; Do you or anyone else has any other ideas?
&#164;
&#164; Could it be a bug in .NET framwork 2.0?
&#164;
&#164; I will go with my working alternative for now, but it would be nice to have
&#164; the commandBuilder working...
&#164;
&#164; Best regards
&#164; 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
~~~~
Microsoft MVP (Visual Basic)

Anders R

4/7/2006 3:00:00 PM

0

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...
> On Tue, 14 Mar 2006 11:42:03 +0100, "Anders R" <abc@cnn.com> wrote:
>
> &#164; Hi Paul,
> &#164;
> &#164; Thanks fo your answer.
> &#164;
> &#164; I have tried with the barckets, but without any success. I use C# btw.
> &#164; Do you or anyone else has any other ideas?
> &#164;
> &#164; Could it be a bug in .NET framwork 2.0?
> &#164;
> &#164; I will go with my working alternative for now, but it would be nice to
> have
> &#164; the commandBuilder working...
> &#164;
> &#164; Best regards
> &#164; 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
> ~~~~
> Microsoft MVP (Visual Basic)