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

isPrimaryKey, Assigning Primary Key in VB.net

New to programming and got a question. I'm trying to add a primary key in vb.net to a table I made in SQL. The table in SQL does not have a primary key. I pull that table into my program and concatenate two columns and assign a series of numbers from a for loop to rows with nulls, to make a third column that is unique enough to be a primary key.

This is where i'm getting stuck. I'm trying to figure out how to assign a primary key in VB after i've pulled the data in from SQL.

Dim pkColumn(0) As DataColumn


pkColumn(0) = DS.Tables("CBOEOI").Columns("CompleteSymbol")
DS.Tables("CBOEOI").PrimaryKey() = pkColumn


adaptor.UpdateCommand = cmdBuilder.GetUpdateCommand()
adaptor.Update(DS.Tables("CBOEOI"))

If I run this I get

"{"Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information."},

which indicates to me that the primary key wasn't set.

I've tried to set up isParentKey without much luck. I've done:

'test to determine if parent key was established
'datarelation = New DataRelation("CS", DS.Tables("CBOEOI").Columns("CompleteSymbol"), DS.Tables("CBOEOI").Columns("CompleteSymbol"), False)
'DS.Relations.Add(datarelation)
'datarelation = DS.Relations("CBOEOI")
'uconstraint = datarelation.ParentKeyConstraint

'If uconstraint.IsPrimaryKey Then
' MsgBox("CompleteSymbol is the primary key")
'Else
' MsgBox("doh")

'End If

But I can't figure out how to make it work without multiple tables. I get a both tables are the same error which is what I want since I only use one column for a key.

Any suggestions for how to resolve this would be greatly appreciated.
Feb 28 '08 #1
4 3185
Plater
7,872 Expert 4TB
Looks to me like you get that error because you are trying to have it automatically create an update query for a DataTable that no longer matches the schema of your database table (which also does not have any keys).
Create you own UPDATE command manually, or add a spare column to your SQL table to store the progmatically-computed "primary key"?

Is there a reason why you didn't make a multi-column key in your SQL table?
Feb 28 '08 #2
Looks to me like you get that error because you are trying to have it automatically create an update query for a DataTable that no longer matches the schema of your database table (which also does not have any keys).
Create you own UPDATE command manually, or add a spare column to your SQL table to store the progmatically-computed "primary key"?

Is there a reason why you didn't make a multi-column key in your SQL table?


right in vb and in sql I don't have a primary key. That is what I am trying to figure out how to do. I've wasted so much time trying to google and msdn this problem that I think i'm just gonna give up and make a random value for a primary key in SQL.

My current situation is this:

1. I get 5 txt file
2. I copy that txt file into excel and then parse it
3. Pull data into SQL. There are 5 sheets. All 5 are combined into one one table.
4. VB program pulls some of the dolumns from SQL. There are rows that are identicle. These are usually titles or somesuch and have no value as data. They repeat a few thousand times and have to be ignored or deleted.
5. Take that data and isolate certain fields that show up in rows (and basically nothing else on that row) and assign them repeatedly in a new column.

Ill take taht updated information and send it back to teh SQL table. Create a new table with other data and Query the two.

the schema is different becuase I don't pull all the data from SQL, only the columns I really need. I'l change that and see if it works.

thanks!
Feb 28 '08 #3
right in vb and in sql I don't have a primary key. That is what I am trying to figure out how to do. I've wasted so much time trying to google and msdn this problem that I think i'm just gonna give up and make a random value for a primary key in SQL.

My current situation is this:

1. I get 5 txt file
2. I copy that txt file into excel and then parse it
3. Pull data into SQL. There are 5 sheets. All 5 are combined into one one table.
4. VB program pulls some of the dolumns from SQL. There are rows that are identicle. These are usually titles or somesuch and have no value as data. They repeat a few thousand times and have to be ignored or deleted.
5. Take that data and isolate certain fields that show up in rows (and basically nothing else on that row) and assign them repeatedly in a new column.

Ill take taht updated information and send it back to teh SQL table. Create a new table with other data and Query the two.

the schema is different becuase I don't pull all the data from SQL, only the columns I really need. I'l change that and see if it works.

thanks!
UPDATE:

I made both tables with identicle columns and created a random value in excel. When I pull the data into SQL, I assign it as primary key. It works like a charm but it's an added step for the end user I wish wasn't there. Oh wells, i'll get this program done and then goback and try to figure out how to make it more efficient.
Feb 29 '08 #4
Plater
7,872 Expert 4TB
I don't think you need the number to be there, just the column.
The column can be empty and you fill it in progmatically.
I do this frequently.
I'll pull a spare column in my query and populate it in my code and use it as a temp-value column tpye thing.
Feb 29 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: cjm | last post by:
I need to group records and assign a setid to the group. I have a table with data that looks like this ColA ColB 94015 01065 94016 01065 94015 01085 94015 01086 33383 00912 32601 00912
3
by: mfyahya | last post by:
I have a table `books` with booktitle and authorname columns. In my applicatoin booktitle has unique values but authorname doesn't. ie an author can have many books but not the other way around. ...
3
by: . . | last post by:
Hi I am creating new SQL Server Tables using SQL Server 2005. I have set primary key to the tables .But I do not know how to assign Foreign key to the tables .I need to do some joins later and...
3
by: Bernie Yaeger | last post by:
Is there a way in MS Access to assign a PK to a table through a query. I am creating the table with 'select .... into <tablename> from etc' which works fine, once executed with executenonquery. ...
3
by: gaffar | last post by:
Sir, if we want to assign a primary key to a single cloumn. below code is used. objTable1.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyPrimary, "PrimaryKey_Field") if i want to assign...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
5
by: jacob.dba | last post by:
I have a table with first name, last name, SSN(social security number) and other columns. I want to assign group number according to this business logic. 1. Records with equal SSN and (similar...
5
by: Phil Latio | last post by:
I have 2 virtually identical tables and wish to move data between them. Basically one table is called "live_table" and the other is named "suspended_table" and the only difference is that the...
2
by: thomasryder | last post by:
I have a Form with a subform which also has a subform. The Primary Form represents a medical invoice. The First subform represents the various services associated with the invoice. The subform on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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: 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,...

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.