473,405 Members | 2,210 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,405 software developers and data experts.

Change table properties using C#



Hello,

I'm using the sql statement below to create a new table from an old one.

But I found a little problem with that.

In my old table DEP2004, I have one field's property allow zero length
is YES, but after creating the new table DEP2005, this property change
to NO. It means it won't allow zero lenght.. How can I change this
property in C#?

My database is stored in Access.

Could someone know how should I do?
Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
6 2684
First off, I didn't see a SQL statement, so I don't know if there is much
help that I can be there.

Second, it doesn't sound like C# is really the issue here. If you have a
SQL statement that works in Access, then whether you use C# or VB.NET to
invoke it shouldn't matter. What code is being used to execute the SQL
statement to change the table definition?

--
Bruce Johnson [C# MVP]
http://www.objectsharp.com/blogs/bruce
"Claudia Fong" wrote:


Hello,

I'm using the sql statement below to create a new table from an old one.

But I found a little problem with that.

In my old table DEP2004, I have one field's property allow zero length
is YES, but after creating the new table DEP2005, this property change
to NO. It means it won't allow zero lenght.. How can I change this
property in C#?

My database is stored in Access.

Could someone know how should I do?
Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #2

This is the code:
SELECT * INTO DEP2005
FROM DEP2004
WHERE (1=0);

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3

"Claudia Fong" wrote...
In my old table DEP2004, I have one field's property allow zero length
is YES, but after creating the new table DEP2005, this property change
to NO. It means it won't allow zero lenght.. How can I change this
property in C#?

My database is stored in Access.

Could someone know how should I do?


It's a bit tricky, but this method should work.
It worked for me when I tried... ;-)

You need to use some extra dll:s, one is straightforward, adodb.dll.

The other one is a COM-dll. If you're using VS.NET, you'll find it in the
COM-list as

Microsoft ADO Ext 2.8 for DDL and security

...which will be imported to your directory as interop.adox.dll
Anyway, here's the code:
private static void SetColumnAllowZeroLength(
string cnstring, string tablename, string columnname)
{
// open connection
ADODB.ConnectionClass conn = new ADODB.ConnectionClass();
conn.Open(cnstring, "", "", 0 );

// Create a catalog
ADOX.CatalogClass cat = new ADOX.CatalogClass();
cat.ActiveConnection = conn;

// fetch the table
ADOX.Table table = cat.Tables[tablename];

// fetch the column
ADOX.Column col = table.Columns[columnname];

// fetch the property and set it
ADOX.Property prop = col.Properties["Jet OLEDB:Allow Zero Length"];
prop.Value = true;

// finish up
col = null;
cat = null;
conn.Close();
conn = null;
}
// Bjorn A


Nov 17 '05 #4
Nothing in that particular SQL statement sets the properties in the new
table. That is to say that the execution of the SELECT statement isn't going
to create the DEP2005 table. So if you're looking for reasons that the table
property has changed, you'll have to look somewhere else.

--
Bruce Johnson [C# MVP]
http://www.objectsharp.com/blogs/bruce
"Claudia Fong" wrote:

This is the code:
SELECT * INTO DEP2005
FROM DEP2004
WHERE (1=0);

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #5

Thanks Bjorn,

Did you try this code with more than one tables?

I need to change that property in 3 tables....
Should I put this way?
ADOX.Table table = cat.Tables[tablename1, tablename2, table3name];?

Can you help me with this again Bjorn?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #6

"Claudia Fong" wrote...

Thanks Bjorn,

Did you try this code with more than one tables?
Sure. The method I wrote simply is an example on how to change the property
on a single column in a single table from a single connection, but it can
easily be rewritten to take care of many columns at the time.
I need to change that property in 3 tables....
You really don't change it on any *table*, as just columns can have that
property... ;-)
Should I put this way?
ADOX.Table table = cat.Tables[tablename1, tablename2, table3name];?


Nope, but simply fetch each table in a separate turn:

ADOX.Table table1 = cat.Tables[tablename1];
ADOX.Table table2 = cat.Tables[tablename2];
ADOX.Table table3 = cat.Tables[tablename3];

....and from respective table fetch each column you want to change the
property on, e.g.:

ADOX.Column col1 = table1.Columns[columnname];
ADOX.Column col2 = table2.Columns[columnname];
ADOX.Column col3 = table3.Columns[columnname];

Remember to change the signature of the method to reflect what arguments you
need to do this, or you can also use literals directly:

ADOX.Table table1 = cat.Tables["MYTABLE"];
ADOX.Column col1 = table1.Columns["MYCOLUMN"];

....etc.
// Bjorn A
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Csaba2000 | last post by:
How do I detect when the font size has been changed (especially by user action: either Ctrl+Scroll wheel or View/Text Size)? This is just for use on IE 5.5+, but it would be great if there was a...
14
by: Reply Via Newsgroup | last post by:
Folks, Say I have a table, ten columns, ten rows - Each with a word in it. I want to change the values of some/all of the cells in the table via a hyperlink. How do I reference each cell and...
13
by: Andrew | last post by:
I use conditional compiler constants, set through the VBA IDE in Tools, <projectname> Properties, that I refer to throughout my code to control which code is used during development, and which...
3
by: sparks | last post by:
I was copying fields from one table to another. IF the var name starts with milk I change it to egg and create it in the destination table. It works fine but I want to copy the description as...
2
by: Tim Frawley | last post by:
I am attempting to change the ODBC Link Provider String in an Access database linked to an Oracle server using ADOX in VB.NET. I created some code using the example from post:...
2
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What...
1
by: Jim M | last post by:
After learning that the 'subdatasheet name' property set to "" can adversely effect database speed, I wanted to send a small code snippent to my end users to reset the SubdatasheetName Property so...
8
by: mlwerth | last post by:
Dear Access Group: This is the most basic and most embarrassing of questions, but I cannot find where to change the data type of a text field that I have in Access 2003 to a number field. I've...
6
by: gavy7210 | last post by:
hello i am using struts 1.2,Eclipse Platform Version: 3.4.2,mySql 5.0.1,jdk 1.5.. i have a login form(jsp) in which a user logs in,in case he doesnt enter his username and/or password an error...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.