473,416 Members | 1,525 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,416 software developers and data experts.

How to create a checkbox datatype column in a table in VB .net code

I am creating a new boolean column in a MSAccess .mdb database like
this:

Dim Cmd As New OleDb.OleDbCommand("ALTER TABLE m_table ADD boolColumn
YesNo", objConn)
Cmd.ExecuteNonQuery()

, which works fine. But... when the .mdb file is opened in Access the
values for the new column are shown as "-1" and "0"...

Is there a way to make the column display in Access as checkboxes? I
want to be able to do this at runtime in my .net program.

thanks.
Jun 27 '08 #1
9 6325
<ev********@gmail.comschrieb
I am creating a new boolean column in a MSAccess .mdb database like
this:

Dim Cmd As New OleDb.OleDbCommand("ALTER TABLE m_table ADD
boolColumn YesNo", objConn)
Cmd.ExecuteNonQuery()

, which works fine. But... when the .mdb file is opened in Access
the values for the new column are shown as "-1" and "0"...

Is there a way to make the column display in Access as checkboxes? I
want to be able to do this at runtime in my .net program.
No, not using OleDb. AFAIK you have to use ADOX (or even DAO) to alter
the format used by the Access aplication to display data. Note that this
is Access specific whereas OleDb only refers to the database part which
does not know a user interface.

Maybe interesting:
http://office.microsoft.com/en-us/ac...322071033.aspx
Armin

Jun 27 '08 #2
Thanks Armin,

Do you have an example of how to do this using DAO?

Evan

On May 1, 8:13 pm, "Armin Zingler" <az.nos...@freenet.dewrote:
<evan197...@gmail.comschrieb
I am creating a new booleancolumnin a MSAccess .mdb database like
this:
Dim Cmd As New OleDb.OleDbCommand("ALTER TABLE m_table ADD
boolColumn YesNo", objConn)
Cmd.ExecuteNonQuery()
, which works fine. But... when the .mdb file is opened in Access
the values for the newcolumnare shown as "-1" and "0"...
Is there a way to make thecolumndisplay in Access as checkboxes? I
want to be able to do this at runtime in my .net program.

No, not using OleDb. AFAIK you have to use ADOX (or even DAO) to alter
the format used by the Access aplication to display data. Note that this
is Access specific whereas OleDb only refers to the database part which
does not know a user interface.

Maybe interesting:http://office.microsoft.com/en-us/ac...322071033.aspx

Armin
Jun 27 '08 #3
On May 1, 8:13 pm, "Armin Zingler" <az.nos...@freenet.dewrote:
<evan197...@gmail.comschrieb
I am creating a new booleancolumnin a MSAccess .mdb database like
this:
Dim Cmd As New OleDb.OleDbCommand("ALTER TABLE m_table ADD
boolColumn YesNo", objConn)
Cmd.ExecuteNonQuery()
, which works fine. But... when the .mdb file is opened in Access
the values for the newcolumnare shown as "-1" and "0"...
Is there a way to make thecolumndisplay in Access as checkboxes? I
want to be able to do this at runtime in my .net program.

No, not using OleDb. AFAIK you have to use ADOX (or even DAO) to alter
the format used by the Access aplication to display data. Note that this
is Access specific whereas OleDb only refers to the database part which
does not know a user interface.

Maybe interesting:http://office.microsoft.com/en-us/ac...322071033.aspx

Armin
Thanks Armin,

Do you have an example of how to do this in .net? Basically, I want to
do this (I think this example is VB6):

Dim f1 As DAO.Field, pt As DAO.Property
Set f1 = CurrentDb.TableDefs("tblCapexCodes").Fields("ColNa me")
Set pt = f1.CreateProperty("DisplayControl", dbInteger, acCheckBox)
CurrentDb.TableDefs("tblCapexCodes").Fields("ColNa me").Properties.Append
pt

(but cannot figure out how to implement it in .net)
Evan
Jun 27 '08 #4
Thanks Armin,

Do you have an example of how to do this in .net? Basically, I want to
do this (I think this example is VB6):

Dim f1 As DAO.Field, pt As DAO.Property
Set f1 = CurrentDb.TableDefs("tblCapexCodes").Fields("ColNa me")
Set pt = f1.CreateProperty("DisplayControl", dbInteger, acCheckBox)
CurrentDb.TableDefs("tblCapexCodes").Fields("ColNa me").Properties.Append
pt

(but cannot figure out how to implement it in .net)
Evan
Jun 27 '08 #5
Thanks Armin,

Do you have an example of how to do this in .net? Basically, I want to
do this (I think this example is VB6):

Dim f1 As DAO.Field, pt As DAO.Property
Set f1 = CurrentDb.TableDefs("tblCapexCodes").Fields("ColNa me")
Set pt = f1.CreateProperty("DisplayControl", dbInteger, acCheckBox)
CurrentDb.TableDefs("tblCapexCodes").Fields("ColNa me").Properties.Append
pt

(but cannot figure out how to implement it in .net)
Evan
Jun 27 '08 #6
On May 1, 8:13 pm, "Armin Zingler" <az.nos...@freenet.dewrote:
<evan197...@gmail.comschrieb
I am creating a new booleancolumnin a MSAccess .mdb database like
this:
Dim Cmd As New OleDb.OleDbCommand("ALTER TABLE m_table ADD
boolColumn YesNo", objConn)
Cmd.ExecuteNonQuery()
, which works fine. But... when the .mdb file is opened in Access
the values for the newcolumnare shown as "-1" and "0"...
Is there a way to make thecolumndisplay in Access as checkboxes? I
want to be able to do this at runtime in my .net program.

No, not using OleDb. AFAIK you have to use ADOX (or even DAO) to alter
the format used by the Access aplication to display data. Note that this
is Access specific whereas OleDb only refers to the database part which
does not know a user interface.

Maybe interesting:http://office.microsoft.com/en-us/ac...322071033.aspx

Armin
Thanks Armin,

Do you have an example of how to do this in .net? Basically, I want to
do this (I think this example is VB6):

Dim f1 As DAO.Field, pt As DAO.Property
Set f1 = CurrentDb.TableDefs("tblCapexCodes").Fields("ColNa me")
Set pt = f1.CreateProperty("DisplayControl", dbInteger, acCheckBox)
CurrentDb.TableDefs("tblCapexCodes").Fields("ColNa me").Properties.Append
pt

(but cannot figure out how to implement it in .net)
Evan
Jun 27 '08 #7
<ev********@gmail.comschrieb
Thanks Armin,

Do you have an example of how to do this using DAO?
http://support.microsoft.com/kb/304274
Look for "Displaycontrol" property. Note it's VBA/VB6 code, and you may
additionally need to call
System.Runtime.InteropServices.Marshal.ReleaseComO bject from VB.Net.
Armin

Jun 27 '08 #8
On May 2, 10:05 am, "Armin Zingler" <az.nos...@freenet.dewrote:
<evan197...@gmail.comschrieb
Thanks Armin,
Do you have an example of how to do this using DAO?

http://support.microsoft.com/kb/304274
Look for "Displaycontrol" property. Note it's VBA/VB6 code, and you may
additionally need to call
System.Runtime.InteropServices.Marshal.ReleaseComO bject from VB.Net.

Armin
I've got it now, thanks Armin.

My main problem was that I needed to include "Microsoft DAO 3.6 Object
Library" into the .net references so that I can use the DAO routines.

Here is my solution for anyone interested (it looks for the column
requested and if it can't find it, creates a bool field/column and
adds the extra parameters using DAO routines to make the field/column
a checkbox):

Public Sub CreateColumn(ByVal ColumnName As String, ByVal
ConnectionString As String)
Dim objConn As New OleDb.OleDbConnection(ConnectionString)
objConn.Open()

'get info about the column
Dim schemaTable As DataTable =
objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Column s, New Object()
{Nothing, Nothing, m_table_name, ColumnName})

'add the requested column if it does not exist
If schemaTable.Rows.Count = 0 Then

'create the new column
Dim Cmd As New OleDb.OleDbCommand(String.Format("ALTER TABLE
{0} ADD COLUMN {1} YesNo", m_table_name, ColumnName), objConn)
Cmd.ExecuteNonQuery()

Dim dbs As DAO.Database
Dim dbe As New DAO.DBEngine

Dim sDbPath As String = "C:\.....mdb"
Dim sDbPassword As String = ""

dbs = dbe.OpenDatabase(sDbPath, False, False, "MS
Access;PWD=" & sDbPassword & ";")

'make the new column a checkbox field (or else the field
displays as "-1" and "0" as "Yes/No")
Dim fld As DAO.Field
fld = dbs.TableDefs(m_table_name).Fields(ColumnName)

dbs.TableDefs(m_table_name).Fields(ColumnName).Pro perties.Append(fld.CreateProperty("DisplayControl" ,
DAO.DataTypeEnum.dbInteger, 106))

dbs.TableDefs(m_table_name).Fields(ColumnName).Pro perties.Append(fld.CreateProperty("Format",
DAO.DataTypeEnum.dbText, "Yes/No"))
dbs.Close()

'cleanup
dbs = Nothing
dbe = Nothing
fld = Nothing
End If

objConn.Close()
End Sub
Note: The "DisplayControl" and "Format" properties are used when
looking at the database in MSAccess
Jun 27 '08 #9
<ev********@gmail.comschrieb
Here is my solution for anyone interested (it looks for the column
requested and if it can't find it, creates a bool field/column and
adds the extra parameters using DAO routines to make the
field/column a checkbox):
Thanks for posting the code. If anybody will stumble across the COM
reference counting issue (if there is any), he will still be able to
ask. (I currently can't post a resolution in advance.)
Armin

Jun 27 '08 #10

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

Similar topics

11
by: Peter Foti | last post by:
Hi all, I have a form that contains a 2 column table. In the left column is the description for a particular input (ie - "First Name", "Last Name", "Phone Number", etc.). In the right column...
2
by: Ryan Lafferty | last post by:
Hi, I have a DataGrid control with a checkbox template column, and want to make the checkbox "disappear" when the 3rd column of the DataGrid contains the string "number". Is what I am trying to...
2
by: Hymer | last post by:
Hello, I have a small two-column table with three rows. The first column has a logo and the second column has the name of the organization. The logo's in the first column are too high. That...
5
by: Hymer | last post by:
Hello, I have a small two-column table with three rows. The first column has a logo and the second column has the name of the organization. The logo's in the first column are too high. That...
10
by: ste | last post by:
Hi there, I'm trying to query a MySQL database (containing image data) and to output the results in a HTML table of 3 columns wide (and however many rows it takes) in order to create a basic...
0
by: NEMA | last post by:
Hi all, How can i add checkbox template column to a datagird? As i dont want to add all row with a checkbox, it will add a checkbox when it checked that it round 2. can i do it with VB.NET...
1
by: akress | last post by:
Hiya, I'm trying to convert a table with 6 colums that looks like this: <table class="myTable" width="640px"> <tr> <td><a href="#"> <img src="../_img/announce.gif" align="middle"...
13
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I want to create a new column in a datatable from two existing columns. I have no problem to create the new column using the datatable.columns.add method. The problem is the value of the new...
2
by: ncsthbell | last post by:
I have a string datatype column which contains values such as '1841000'. The value should be '18410'. I have tried the following: Replace(RTrim(Replace(MyValue, "0", " ")), " ", "0") The problem...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.