|
I have a table with field ID int IDENTITY(1,1) (primary key)
So lets say I have only two elements, with ID=1 and ID=2.
So if admin (id=1) remove element where ID=2 and then add a new element, I will have an element with ID=3 and not with the ID=2. (so table will have two elements one with id=1 and another with id=3 instead id=2)
Why this happens?
|
|
|
|
|
Maxdd 7 wrote: Why this happens?
This is how identity columns works.
Best wishes,
Navaneeth
|
|
|
|
|
N a v a n e e t h wrote: This is how identity columns works.
There is not a way that usually there's no way do alter value of the primary key.
So I suppose thats not possible to do something around that, am I right?
|
|
|
|
|
Maxdd 7 wrote: There is not a way that usually there's no way do alter value of the primary key.
What do you meant by that?
Most database systems won't reuse the identity value. It will always increase when new rows are added.
Best wishes,
Navaneeth
|
|
|
|
|
First of all your question is nothing to do with ASP.NET .
This is not the auto increment problem, that is what Identity Works
For Better Info : Read This[^]
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
IDENTITY columns are designed to work this way. If you want to reuse identity values for some reasons, you can reseed the identity column using:
DBCC CHECKIDENT("Table1", RESEED, 2)
When you insert a new row after executing this statement, your ID column will start from 2 again.
|
|
|
|
|
Good Day Maxdd 7
as the guys says , that is how identity works. Delete and Truncate Works Differently. The Delete will continue from the previous seed but Truncate will start from the beginning. lets say i have this
Table1
<pre>
=============
ID | Name
=============
1 | Vuyiswa
2 | Maxdd 7
3 | Maxdd 8</pre>
if i have to Delete ID 3 and later i add a new Record. It will continue as ID 4 but if you truncate(this not a Good idea) the table and add the Records to a Temp table and insert in the very same table from a temp table you will get the records with ordered ID.
Hope you understand this.
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
modified on Friday, November 27, 2009 9:12 AM
|
|
|
|
|
Vuyiswa Maseko wrote: The Delete will not continue from the previous seed
Did you mean to say "The Delete will continue from the previous seed" ? Because this is what is correct.
|
|
|
|
|
Oops i fixed it thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Thank you guys I was just curious about the reason but now I understand
|
|
|
|
|
You are Welcome
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I have a dropdownlist who's datasource is a ObjectCollection. I have 3 variables within the Object. The Dropdown list works fine and shows the name variable from the object. Below is some code that explains what i'm doing however I get a compiler error that the cast can't be done.
int number = ((Object)dropdownlist1.selecteditem).num;
For some reason i get a cannot convert a type system.web.ui.listitem to projectname.int
Any ideas?
|
|
|
|
|
It is because you converted the selecteditem to an object which doesn't have the num property.
What is projectname.int? projectname is a class? Can you please show the code that you use to bind the dropdownlist?
|
|
|
|
|
Running VS 3.5 ASP.NET I can update text file in \res subdirectory, and
SQL database in \App_Data; but when I run same under IIS (5.1 under XP Pro)
it says 'access to path denied' for text file, and 'db is read-only' for SQL.
IIS is set to allow anonymous users; config is set to authentication None.
There is lots of information about how to protect your files, but nothing about how NOT to. Clearly some default protection is kicking in, but I have
been unable to figure out where or how to turn it off. Any help would be
greatly appreciated.
|
|
|
|
|
Hi,
Isn’t that ACL list problem? Right click to the file/directory -> properties -> security tab -> check if the ASP .NET user has permission to that object?
|
|
|
|
|
Thanks for responding, Petr.
You are quite right; but to be able to set ACL permits I had to turn off
simple file sharing. I have now tried doing this, and it seems to work.
I had originally assumed if it was on, any process would have access to everything. Does this mean that IIS ignores file sharing, and can't be used without that being turned off?
Also, I had thought that Windows permits would only come into play if
one used Windows authentication; I gather this means authentication and
authorization are unrelated. In which case what I still don't understand is
what happens in the case of web hosting: does it mean the hosting provider
has to go around setting my file permissions, and that I have no control
over that (except perhaps to restrict things)? For example, how do I ensure
my program can update my database, but others can't?
I would appreciate any further comments.
|
|
|
|
|
Hi,
As far as I remember about Windows internal security, every process is running under an account. This account has to be authenticated in the system of course. This is same in case of ISS. There is the process running under ASP.NET user and if you want to manage some files in this process, the ASP.NET user has to have permission for it. This is usual scenario. But........... there is always option to do the impersonation and switch the current process to another context (user).... but that is long story.
In case of web hosting you have to ask admin to set up the ACL. However, nowadays people managing web hosting know, you will need "write" access to App_Data folder, thus it is usually set up in this way.
For example, how do I ensure my program can update my database, but others can't?
This is another thing. Using database login is the right way.
modified on Friday, November 27, 2009 4:58 AM
|
|
|
|
|
Hi, I am having some trouble with creating a simple function that converts a column of a datatable to an array (containing all numbers). Upon running it, it says "Index was outside the bounds of the array"; however, I couldn't understand why my function would create this problem.
Also since I do not usually program using VB.Net, I am not sure if my function has other errors (like syntax errors). Could you please help me check it out? I'd greatly appreciate it! Thanks in advance.
Here's my VB function:
Public Function DatatableToArray(ByVal dt As DataTable, ByVal intColomn As Integer) As Double()<br />
Dim intRows As Integer = dt.Rows.Count<br />
Dim arrValues() As Double = New Double(){}<br />
Dim i2 As Integer<br />
For i2 = 0 To intRows - 1<br />
arrValues(i2) = dt.Rows(i2).Item(intColomn)<br />
Next<br />
Return arrValues<br />
End Function
|
|
|
|
|
Check the value in intColumn variable.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
I'm not really confirm with the VB-Syntax but
arrValues(i2) = dt.Rows(i2).Item(intColomn)
looks like you try to access an double array that is not initialized (or doesn't have enough space).
Look at you definition:
Dim arrValues() As Double = New Double(){} <- maybe here you should say that this array should have
dt.Rows.Count elements
Greetings
Covean
|
|
|
|
|
Declare arrValues with a specific size.
Like this
Dim arrValues() As Double = New Double(dt.Rows.Count - 1) {}
|
|
|
|
|
First of all why dont you use List .... as your collection. It is always better to use ArrayList or Generic List as collection rather than going for Array.
Next, I always prefer to use ForEach rather than For when I am looping through an Enumerable .
If I was in your situation I would write this as :
Private Function DataTableToArray(ByVal x As DataTable, ByVal intCol As Integer) As List(Of Double)
Dim lst As New List(Of Double)
For Each dr As DataRow In x.Rows
lst.Add(dr.Item(intCol))
Next
Return lst
End Function
Or if you still want to use Array you might use List(Of Double).ToArray as well.
Cheers.
|
|
|
|
|
Thanks a lot guys. As soon as I'm home I'll give all of these options a try.
|
|
|
|
|
Hi, try the following code:
Dim arrValues(0 To intRows - 1) As Double
instead of
Dim arrValues() As Double = New Double(){}
modified 27-May-14 5:11am.
|
|
|
|
|
Thank you guys, my problem is solved!
Greatly appreciate it.
|
|
|
|