Multi Column Primary Key's In Access Using ADOX [c#]
Jan 15, 2008
Hi all,
I have been pulling my hair trying to figure out what the guys at microsoft were thinking when creating the ADOX library. I have an access table that is syncronized with a SQL server. The table has a primary key with two columns [User] and [Program]. The SQL Server has both columns in as the primary key columns and I have a syncronization mechanism that is responsible for several things, one of which is to recreate the Access data structure. All works well for all tables except this one. I have tried to create the multi-column key in several ways, none that worked. Let me show you what I am doing:
I want to add new column 'firstaname' into the existing table "geo" already two columns namely
'salcode' 'lastname'.I run the following code it runs without error, when i opened the database see the structure of table, i didn't find new column in the table "geo"
I need to programatically create a mdb file which will contain nullable columns. I am using C++ with ADOX for the table creation and ADO to perform the table update.
Although ADOX seems to create the table ok, Table->Columns->Appends does not set the fields as adColNullable as expected.
When I insert data using ADO::Recordset->AddNew the following error occurs :- "The field 'MyTable.Column 2' cannot contain a Null value because the Required property for this field is set to True. Enter a value in this field."
Am I on the right tracks here or do I need to adopt a different approach?
I'm using ADOX 2.8 for table creation: The following is an example of a column defintion:
If CreateNewTable Then CreateNewTable = a.CreateColumn("ReferenceCount", ADOX.DataTypeEnum.adInteger)
If CreateNewTable Then CreateNewTable = a.CreateColumn("Document", ADOX.DataTypeEnum.adLongVarBinary) 'Oleobject
If CreateNewTable Then CreateNewTable = a.CreateColumn("EntityID", ADOX.DataTypeEnum.adWChar, 18) 'text
Where CreateColumn looks like this:
Public Function CreateColumn(ByVal ColumnName As String, ByVal Datatype As ADOX.DataTypeEnum, Optional ByVal Size As Integer = 0) As Boolean
'ADOX.CreateColumn - Called by Common.CreateNewTable 'CreateColumn creates a column described in the Table object so it assumes it is set. 'One method of setting it is to call Select Table after opening the database
If Not Me.ConnectionIsOpen Then MsgBox("CreateColumn - Failed to Create Column : " _ & ColumnName, MsgBoxStyle.Exclamation, cNoConn) Return False End If
Dim col As New ADOX.Column col.Name = ColumnName Try col.Type = Datatype Catch e As Exception MsgBox("CreateColumb - Failed to Create Column : " _ & ColumnName, MsgBoxStyle.Exclamation, e.Message) col = Nothing Return False End Try
If Size <> 0 Then col.DefinedSize = Size Try
Table.Columns.Append(ColumnName, Datatype)
Catch e As Exception If Err.Number() <> 0 Then MsgBox(Err.Source & "-->" & Err.Description, , "Error") End If MsgBox("CreateColumb - Failed to Append Column : " _ & ColumnName, MsgBoxStyle.Exclamation, e.Message) Return False End Try col = Nothing Return True End Function
in CreateColumn("EntityID", ADOX.DataTypeEnum.adWChar, 18)
the 18 specifies the field width in the database. Yet no matter whether I use adWChar or
adVarWChar, Access always shows the field size to be 255.
I have a table (table1) that has a bunch of fields....[field1][field2][field3][field4][field5]None of these fields are unique, but if I combine them, then they areunique.I know there is a way to make multi-field primary keys, but when I tryI get an that field1 is not unique, which I already know,How can I make a multi-field primary key?thanks
I've been developing desktop client-server and web apps and have used Access and SQL Server Standard most of the time. I'm looking into using SQL CE, and had a few questions that I can't seem to get a clear picture on:
- The documentation for CE says that it supports 256 simultaneous connections and offers the Isolation levels, Transactions, Locking, etc with a 4GB DB. But most people say that CE is strictly a single-user DB and should not be used as a DB Server. Could CE be extended for use as a multi-user DB Server by creating a custom server such as a .NET Remoting Server hosted through a Windows Service (or any other custom host) on a machine whereby the CE DB would run in-process with this server on the machine which would then be accessed by multiple users from multiple machines?? Clients PCs -> Server PC hosting Remoting Service -> ADO.NET -> SQL CE
- and further more can we use Enterprise Services (Serviced Components) to connect to SQL CE and further extend this model to offer a pure high-quality DB Server? Clients PCs -> Server PC hosting Remoting Service -> Enterprise Services -> ADO.NET -> SQL CE
Seems quite doable to me, but I may be wrong..please let me know either ways
I am trying to exclude records from a table where the ID column is the same but the Mail code Column is multi-valued.For Example: (the table looks like....)
I have two tables, one a data table, the other a product table. I want to perform a join on the two tables with values distributed into columns based on the value in the month field.
Hi,Would like to know the performance differenece between Multi-columnIndex vs Single Column Indexes. Let's say I have a table with col1,col2, col3 along with a primary key column and non-indexed columns.In queries, I will use col1, col2, and col3 together and some timesjust one or two of these three columns. My questions is, should Icreate one index contains col1, col2, and col3, or create 3 seperatedcolumns. I.e. each column has its own index. Any performancedifference?Thanks a lot.
We have a database where many tables have a field that has to be lengthened. In some cases this is a primary key or part of a primary key. The table in question is:-
/****** Object: Table [dbo].[DTb_HWSQueueMonthEnd] Script Date: 09/25/2014 14:05:09 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[DTb_HWSQueueMonthEnd](
[Code] ....
The script I am using is
DECLARE@Column varchar(100)--The name of the column to change DECLARE@size varchar(5)--The new size of the column DECLARE @TSQL varchar(255)--Contains the code to be executed DECLARE @Object varchar(50)--Holds the name of the table DECLARE @dropc varchar(255)-- Drop constraint script
[Code] ....
When I the the script I get the error message Could not create constraint. See previous errors.
Looking at the strings I build
ALTER TABLE [dbo].[DTb_HWSQueueMonthEnd] DROP CONSTRAINT PK_DTb_HWSQueueMonthEnd ALTER TABLE [dbo].[DTb_HWSQueueMonthEnd] Alter Column [Patient System Number] varchar(10) ALTER TABLE [dbo].[DTb_HWSQueueMonthEnd] ADD CONSTRAINT PK_DTb_HWSQueueMonthEnd PRIMARY KEY NONCLUSTERED ([Patient System Number] ASC,[Episode Number] ASC,[CensusDate] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
They all seem fine except the last one which returns the error
Msg 8111, Level 16, State 1, Line 1 Cannot define PRIMARY KEY constraint on nullable column in table 'DTb_HWSQueueMonthEnd'. Msg 1750, Level 16, State 0, Line 1 Could not create constraint. See previous errors.
None of the fields I try to create the key on are nullable.
We€™re calling ADOX::Table::Keys::Append to make a primary key for a table using the SQLOLEDB provider. We€™re passing an ADOX::Key with Name set to a custom name, Type set to ADOX::adKeyPrimary, and a single column added. For the Append call, the 2nd parameter is ADOX::adKeyPrimary, the third is a vtMissing (VT_ERROR with DISP_E_PARAMNOTFOUND), the last two are empty BSTR€™s. On XP, this works well (msadox.dll file version 2.81.1117.0). On Vista, this fails with an invalid parameter error (msadox.dll version 6.0.6000.16386). Has the interface changed in some way, is this functionality not supported, or is it broken?
Hello,I am working on an Access VBA application, working in client/servermode, with a shared SQL Server base.I have to INSERT some data in the base, and the know what is the IDthat SQL Server associated with my data in the table. So I need to dothe followingINSERT data INTO TABLESELECT MAX ID FROM TABLE (to get the ID)but since I am working in client/server, if some DATA has been insertedby another client after my INSERT, then MAX ID is not the convenientID of my data ...Is there a way for me to get the ID when I do the INSERT, or tolock/unlock the table before the INSERT and after the SELECT ?Thank you for any hint about that.--L'ordinateur peut faire plus de calculs que le cerveau de l'homme caril n'a que ça à faire
I have developed two programs that operates against the same database. One of the program is just a display program that displayes the data put into the other administation program where you put in the data to be displayed (an administration program).
Every time I access the db from the administration program, the display program stops and throws connection pool errors and other database errors. For me, it looks like it does´t do multi-access to a database.
I have tried putting user instance to off in both programs, but this didn´t help.
Connection string also points to same file database.
Please help.... I have designed an application that uses sql server 2005 express database. This application was intended to be installed and used on a local desktop machine. However, now this application needs to be also installed on several computers and still needs to use only 1 database. Part of the database saves local user settings, so what I have done thus far is use two connection strings: one for local database (because the application may be used as origionally intended) and one for remote database that everyone should be able to connect to.
When I remotely connect to the database, it works fine. However, it seems to be locked so when I chose the same database for another user I get the error message "This File Is In Use." I need to know how to unlock it and make it usable for several users at the same time.
Thank you for your help! Please let me know if you need more information or if something is unclear in my description.
I have 6 columns: Column1a, Column1, Column2a, Column2, Column3a, Column3
I need a statement that will go through the whole table as follows: For each row, if column3 is not null then return column3 as columnB and column3a as ColumnA. If column3 is null then if column2 is not null then return column2 as columnB and column2a as columnA. If column3 & column2 is null then return column1 as columnB and column1a as columnA.
Price ----- 777 888 999 777 888 999 777 888 999 (pretend these columns are side by side) ======================
I need to make a query to: SELECT PRICE AS 'PRICE1' WHERE PRICELIST = 1 AND SELECT PRICE AS 'PRICE2' WHERE PRICELIST = 2 AND SELECT PRICE AS 'PRICE3' WHERE PRICELIST = 3
the output that i want is:
PRICE1 ------ 777 777 777
PRICE2 ------ 888 888 888
PRICE3 ----- 999 999 999 (pretend these columns are also side by side)
I have a [TestTable] table with three rows. The pair of columns [Test1] and [Test2] are id, the [Test3] is a data column. First, I get a table variable with list of id pairs. Next, I would like to update the rows of that ids. However, I have not found the elegant way how to do it. For one column it is simple, just IN clause, which does not work (or I could not find how) for multi-columns. Does someone have a hint?
Thanks,
Martin
Note: The example bellow is dummy; on the other hand, I hope it shows the important points. Please, do not beat me on syntax errors.
Code Block DECLARE @MyTableVar table( Test1 int NOT NULL, Test2 int NOT NULL );
SELECT [Test1],[Test2] INTO @MyTableVar FROM [TestTable] WHERE [Test3] = '%dd%';
UPDATE [TestTable] SET [Test3] = [Test3] + 'ds' WHERE ([Test1], [Test2]) IN (SELECT [Test1], [Test2] FROM @MyTableVar);
What I need to do is to create 3 columns with 3 different aliases from the same table that will return all the values during the following conditions:
when pricelist = 1
when pricelist = 2
when pricelist = 3
pricelist -------- 1 2 3
Price -------- 912 -- (linked with 1) 234 -- (linked with 3) 56 -- (linked with 2) 3245 -- (linked with 3) 234 -- (linked with 1) 65 -- (linked with 2)
these 2 columns are in the same table^^
so what i want my query to generate is:
Price1 -------- 912 234
Price2 -------- 56 65
Price3 -------- 234 3245
Any help is apprecieated, thanks
if the above does not make sense to you maybe this will: "can you make 3 aliases of the same column and only display the rows inside each column where pricelist = 1 for the 1st alias... where price = 2 for the 2nd alias...where pricelist = 3 for the 3rd alias"
I have a 2 coulmns report ,one group ,when I print the report,it does not paging correctly.For example,suppose every column can display 20 rows, if every group has 20-40 rows ,the print is ok,it can paging correctly,but if one group has 10 rows or more than 40 and less than 60,the two groups will print on one paper,how can I print the every group on different paper?
Hi, I have created a multi column report (2 columns), which is working fine. However, I need to have a chart on the same report, but it needs to be the width of the page, and not just the width of one column.
If I could put the chart in the report footer / header that would be perfect, but obviously I can't!
Has anyone else come across this, and any ideas / suggestions you have would be appreciated!
I am trying to get a simple list to wrap and print in multiple columns on my report. I have indicated 3 multi-columns in the report properties and see the multiple columns in the layout, but I must need to do something else because the report is still printing in one column to multiple pages. This should all fit on 1 page if the list will wrap or snake as it says it the directions for using multi-column reports.
Hi, I have got a column which should multi languages data(Chinese,English etc). Source for this data is Excel. I have kept this column DataType as NVARCHAR but Chinese data is shown as 'Boxes'.But when i copy this and paste on Query pane i get proper data.