|
-
Nov 8th, 2007, 07:00 AM
#1
Thread Starter
Frenzied Member
Identity Issue ???
Hi Peeps,
I have had to add an Identity column to my sqlce table because it complains of no primary key when doing a delete row. The problem is how do I handle the identity in sqlCE? I know how to do it in OLEDB!
Any ideas please?
Jiggy!
-
Nov 8th, 2007, 09:15 AM
#2
Re: Identity Issue ???
What do you mean by 'handle'?
I assume the Identity column will be used as an autonumber, right?
-
Nov 8th, 2007, 09:23 AM
#3
Thread Starter
Frenzied Member
Re: Identity Issue ???
Yes mate, I have wrote a routine which gets the MAX of my autonumber so I add one to it and assign that to my auto number.
-
Nov 8th, 2007, 05:05 PM
#4
Fanatic Member
Re: Identity Issue ???
in order to delete columns in a table you need some value that distinguishes each row from each other. therefore a primary key.
you can use a identity field where you provide the starting number and the incremental amount (100,1) means starts at 100 and increments by 1, there is no need to create a function for it
hope it answers what you are looking for
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Nov 9th, 2007, 04:48 AM
#5
Thread Starter
Frenzied Member
Re: Identity Issue ???
Hi Mate,
I created an identity field which started at 1 and incremented by one but it did not seem to work. I know in VB.NET you have to do SELECT @@ on the row update to get the next ID. In the end I changed the identity column to an int as primary key and used my function (Get MAX) to get the next ID.
Cheers for your help,
Jiggy!
-
Nov 9th, 2007, 12:19 PM
#6
Frenzied Member
Re: Identity Issue ???
What doesn't work?
You just need to do an insert, with a list excluding the identity field, and the identity field will sort itself out
-
Nov 9th, 2007, 12:55 PM
#7
Thread Starter
Frenzied Member
Re: Identity Issue ???
Ah, I was using the command builder which will probably also work but in my select sql I used * which would have included the identity field. I will try without the identity field!
-
Nov 14th, 2007, 04:11 PM
#8
Thread Starter
Frenzied Member
Re: Identity Issue ???
Still cant get this to work properly. If I delete a row and then insert one I get a concurrency issue. Here is my save code:-
Code:
sqlDRStoreContact = sqlDSStoreContacts.Tables(0).NewRow
sqlDRStoreContact("SC_ST_STORECODE") = cboStore.SelectedValue
sqlDRStoreContact("SC_JT_CODE") = cboJobTitle.SelectedValue.ToString
sqlDRStoreContact("SC_JT_NAME") = cboJobTitle.Text.ToString
sqlDRStoreContact("SC_NAME") = txtContactName.Text.ToString
sqlDRStoreContact("SC_RECORD_STATUS") = "NEW RECORD"
sqlDSStoreContacts.Tables(0).Rows.Add(sqlDRStoreContact)
sqlCBStoreContacts = New SqlCeCommandBuilder(sqlDAStoreContacts)
sqlDAStoreContacts.Update(sqlDSStoreContacts, "SC_STORE_CONTACTS")
And here is my delete code:-
Code:
sqlDSStoreContacts.Tables(0).Rows(dgContacts.CurrentRowIndex).Delete()
sqlCBStoreContacts = New SqlCeCommandBuilder(sqlDAStoreContacts)
sqlDAStoreContacts.Update(sqlDSStoreContacts, "SC_STORE_CONTACTS")
Thanks for any help,
Jiggy!
-
Nov 14th, 2007, 04:19 PM
#9
Thread Starter
Frenzied Member
Re: Identity Issue ???
The thing is if I don't include the identity field it works on the delete but the update fails and if I dont include it the delete fails. How do I get them both to work????
-
Nov 14th, 2007, 04:41 PM
#10
Thread Starter
Frenzied Member
Re: Identity Issue ???
OK I have used the insert command but this inserts it direct into the database which is great but I have a datagrid with a dataset bound to it and it does not show it there. Any ideas please
Jiggy!
-
Nov 15th, 2007, 03:14 AM
#11
Frenzied Member
Re: Identity Issue ???
Hi,
not without some explanation of the code, or seeing the code 
Pete
-
Nov 15th, 2007, 05:26 AM
#12
Thread Starter
Frenzied Member
Re: Identity Issue ???
My code is above mate. I think I know what is happening; if I do a new row that works fine and the identity number is stored in the database but I don't think it is returning to the dataset so when I delete that record I get a concurrency error. Here is the insert I tried which puts it into the database fine but not in my dataset so the bound grid looks like it hasn't worked.
Code:
'Dim sqlInsertRow As SqlCeCommand = CeData.CreateCommand()
'sSQL = "INSERT INTO SC_STORE_CONTACTS(SC_ST_STORECODE, SC_JT_CODE, SC_JT_NAME, "
'sSQL = sSQL & "SC_NAME, SC_RECORD_STATUS) VALUES('" & cboStore.SelectedValue & "', "
'sSQL = sSQL & "'" & cboJobTitle.SelectedValue.ToString & "', "
'sSQL = sSQL & "'" & cboJobTitle.Text.ToString & "', "
'sSQL = sSQL & "'" & txtContactName.Text & "', "
'sSQL = sSQL & "'NEW RECORD')"
'sqlInsertRow.CommandText = sSQL
'sqlInsertRow.ExecuteNonQuery()
Thanks for getting back to me mate,
Jiggy!
-
Nov 15th, 2007, 12:13 PM
#13
Frenzied Member
Re: Identity Issue ???
Hi,
I am getting lost to what your problem is now. You asked about a datagrid not showing your record, and then show the insert code.
What exactly is your problem now please?
Thanks
-
Nov 15th, 2007, 12:51 PM
#14
Thread Starter
Frenzied Member
Re: Identity Issue ???
If I use :-
Code:
sqlDSStoreContacts.Tables(0).Rows.Add(sqlDRStoreContact)
sqlCBStoreContacts = New SqlCeCommandBuilder(sqlDAStoreContacts)
sqlDAStoreContacts.Update(sqlDSStoreContacts, "SC_STORE_CONTACTS")
and then delete a that row I get a concurrency error so someone mentioned using the INSERT INTO method. The problem with that is it inserts it directly into the database and not my bound dataset.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|