Hi Yan,
If this is your exact code, I can see one thing: your INSERT statement
should have quotes on both sides of the values (i.e. Values('1', 'Ping',
'800-888-8888'). Otherwise, it almost sounds like ODBC believes the
sheet is not updateable, perhaps ReadOnly=0 in the connection string
would help.
There's a knowledgebase article that uses the OleDb data provider to do
what you want. It's VB.NET so you'll need to do some minor conversion.
http://support.microsoft.com/default.aspx?scid=kb;EN-US;316934#12
Cheers,
Bob Beauchemin
http://staff.develop.com/bobb
-----Original Message-----
From: yan ping [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 15, 2003 3:52 PM
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] ERROR [HY000] [Microsoft][ODBC Excel Driver]
Operation must use an updateable qu
Hi all,
I have a very simple Excel 2002 file called "Target.xls". The file has
just
1 worksheet called "Target". Inside the worksheet, I have defined 3
columns
whose headers are in turn called "TargetId, "TargetName" and
"TargetPhone".
I am just trying to insert one row into the Excel file using Odbc.Net
Driver. BTW, I am using .NET Framework 1.0, but I don't think it
matters.
Below is my code:
string strConnection = @"Driver={Microsoft Excel Driver
(*.xls)};DBQ=C:\Target.xls";
OdbcConnection conn = new OdbcConnection(strConnection);
try
{
conn.Open();
OdbcCommand cmd = conn.CreateCommand();
cmd.CommandText = "Insert Into [Target$] Values
('1, 'Ping, '800-888-8888)";
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
}
It always throws an exception saying "ERROR [HY000]
[Microsoft][ODBC Excel Driver] Operation must use an
updateable query.".
I am stuck and very confused. Where am I wrong???
Any helps are greatly appreciated.
Best regards,
Ping
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail