ALTER TABLE with oledebconnection to MS Access

gsilvey
02-24-2004, 01:44 PM
Can I use the ALTER TABLE command on an existing MS ACCESS database? I have a working connection where I can update frows within the target table, but when I execute the following code:

SQLCommand = "ALTER TABLE Table1 ADD COLUMN Panel1 TEXT"
oleDbCommand = New OleDb.OleDbCommand(SQLCommand)
oleDbCommand.Connection = main.OleDbConnection1
ret = oleDbCommand.ExecuteNonQuery()

I get the following message:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

Any ideas?

MKoslof
02-26-2004, 07:18 AM
There could be numerous reasons for that error. Make sure you have the latest version of MDAC on your computer. And, if you have run code on this same application with no errors, maybe we should look at how you declare this command.

When using ADO.Net I tend to use the command object in order to make manipulations. You could also look into the ADOX library. But here is an example, that may help get you started:



sqlConnection1.Open();

'add a column into a table
'I *believe* for Access you want to use TEXT in .NEt
'I have not done much with Access in .Net, but I assume
'that is still the proper parameter. If not try CHAR()

cmdText = "ALTER TABLE table1 ADD field1 TEXT(200) ";
SqlCommand addColumnCmd = new SqlCommand ( cmdText, sqlConnection1 );
addColumnCmd.ExecuteNonQuery();

sqlConnection1.Close();

gsilvey
03-02-2004, 12:14 PM
There could be numerous reasons for that error. Make sure you have the latest version of MDAC on your computer. And, if you have run code on this same application with no errors, maybe we should look at how you declare this command.

When using ADO.Net I tend to use the command object in order to make manipulations. You could also look into the ADOX library. But here is an example, that may help get you started:



sqlConnection1.Open();

'add a column into a table
'I *believe* for Access you want to use TEXT in .NEt
'I have not done much with Access in .Net, but I assume
'that is still the proper parameter. If not try CHAR()

cmdText = "ALTER TABLE table1 ADD field1 TEXT(200) ";
SqlCommand addColumnCmd = new SqlCommand ( cmdText, sqlConnection1 );
addColumnCmd.ExecuteNonQuery();

sqlConnection1.Close();




Thanks. I changed my code to use ADOX and ADODB and can now add the columns as I desired. Now I'm having trouble binding the columns via adox/adodb.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum