473,786 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2704
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.dl l
Anyway, here's the code:
private static void SetColumnAllowZ eroLength(
string cnstring, string tablename, string columnname)
{
// open connection
ADODB.Connectio nClass conn = new ADODB.Connectio nClass();
conn.Open(cnstr ing, "", "", 0 );

// Create a catalog
ADOX.CatalogCla ss cat = new ADOX.CatalogCla ss();
cat.ActiveConne ction = 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
9563
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 generic solution. Thanks, Csaba Gabor from New York
14
2520
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 change its text contents from a link elsewhere in the page? I have a rought idea that I'll need something like 'id' in my <td> tags but while I have a greater understanding of server-side programming langauges like PHP, javascript is still very new...
13
6114
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 during production. Usually, this only wraps code used to control quitting the whole app versus just shutting a form, but it can also control many other things. However, as part of the build before delivering an update, I have to remember to...
3
2572
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 well. Short version :) For Each fld In tdf.Fields pos = InStr(fld.Name, "milk") If pos > 0 Then
2
8658
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: http://groups.google.com/groups?q=RefreshLinkedTablesWithADOX()&hl=en&lr=&selm=qb1ctvcdoftenojhpp34lb6fjb9ss8qd9c%404ax.com&rnum=1 My code simply replaces the DSN, UID, PWD and DBQ values in the ADOXTable.Properties("Jet OLEDB:Link Provider String").Value string...
2
7989
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 I've done for test purposes is use a text input file for the table field lookup properties. I thought that I'd start first by just changing the 'Display Control' property. Thanks to Allen Browne for some ideals per...
1
11118
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 they don't have to manually cycle through 35 or 40 tables and change the property. VBA help says: "To set the SubdatasheetName property by using Visual Basic, you must first either: -Set the property in table Design view by pointing to...
8
3274
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 searched high and low through help databases and on the internet. The directions say to : Open the table in Design view Click the Data Type column of the field you want to change, click the
6
4525
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 is displayed using the <ul> tag and <html:errors> in the jsp. in the from class a vaidate method creates an actionerrors object adds all the errors to it and finally returns it. the ids are linked in messageresources.properties and appropriate...
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.