943,537 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1883
  • VB.NET RSS
Sep 1st, 2008
0

AutoNumber still a problem !! can ne1 clear the mess?

Expand Post »
I am really at my wits end now....i am unable to find ne proper code for autonumber generation...if i do find its not working. plz i want it ..i am using sql server 2000 and vb.net 2005.
just tell me can we make use of max function ?
ie. first get the max of id and then increment it by 1 ?
like ("select max(id) from tablename)
and then txtbox.text=id+1
however i encounter several errors here...can we do autonumbering this way ??? ne ideas ?
plz help me out....'coz of this am unable to complete my project work...
wating for ur reply

cya
Rohan
Reputation Points: 10
Solved Threads: 2
Junior Poster
laghaterohan is offline Offline
170 posts
since Aug 2008
Sep 1st, 2008
3

Re: AutoNumber still a problem !! can ne1 clear the mess?

Try This :
vb.net Syntax (Toggle Plain Text)
  1. Public Sub GenerateNotaId()
  2. Dim myReader As SqlDataReader
  3. conn = GetConnect()
  4. conn.Open()
  5. Dim temp As String
  6. Try
  7. Dim sql As String = "SELECT MAX(IDNOTA) AS 'KODE' FROM Nota "
  8. Dim comm As SqlCommand = New SqlCommand(sql, conn)
  9. myReader = comm.ExecuteReader
  10. If myReader.HasRows Then
  11. While myReader.Read()
  12. temp = myReader.Item("KODE") + 1
  13. End While
  14. End If
  15. myReader.Close()
  16. Catch ex As Exception
  17.  
  18. End Try
  19. conn.Close()
  20. If temp = 0 Then
  21. txtNoNota.Text = 1
  22. Else
  23. txtNoNota.Text = String.Concat(temp)
  24. End If
  25. End Sub
Generate will shown in txtNoNota
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,135 posts
since Nov 2007
Sep 1st, 2008
0

Re: AutoNumber still a problem !! can ne1 clear the mess?

thanks but still getting an error ! can u plz tell which files to import ???



Click to Expand / Collapse  Quote originally posted by Jx_Man ...
Try This :
vb.net Syntax (Toggle Plain Text)
  1. Public Sub GenerateNotaId()
  2. Dim myReader As SqlDataReader
  3. conn = GetConnect()
  4. conn.Open()
  5. Dim temp As String
  6. Try
  7. Dim sql As String = "SELECT MAX(IDNOTA) AS 'KODE' FROM Nota "
  8. Dim comm As SqlCommand = New SqlCommand(sql, conn)
  9. myReader = comm.ExecuteReader
  10. If myReader.HasRows Then
  11. While myReader.Read()
  12. temp = myReader.Item("KODE") + 1
  13. End While
  14. End If
  15. myReader.Close()
  16. Catch ex As Exception
  17.  
  18. End Try
  19. conn.Close()
  20. If temp = 0 Then
  21. txtNoNota.Text = 1
  22. Else
  23. txtNoNota.Text = String.Concat(temp)
  24. End If
  25. End Sub
Generate will shown in txtNoNota
Reputation Points: 10
Solved Threads: 2
Junior Poster
laghaterohan is offline Offline
170 posts
since Aug 2008
Sep 1st, 2008
0

Re: AutoNumber still a problem !! can ne1 clear the mess?

This some files to import :
vb.net Syntax (Toggle Plain Text)
  1. Imports System.Data
  2. Imports System.Data.SqlClient

what kind of error ??
Last edited by Jx_Man; Sep 1st, 2008 at 9:51 am.
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,135 posts
since Nov 2007
Sep 1st, 2008
0

Re: AutoNumber still a problem !! can ne1 clear the mess?

error like getconnect() not defined.....?
[

QUOTE=Jx_Man;682207]This some files to import :
vb.net Syntax (Toggle Plain Text)
  1. Imports System.Data
  2. Imports System.Data.SqlClient

what kind of error ??[/QUOTE]
Reputation Points: 10
Solved Threads: 2
Junior Poster
laghaterohan is offline Offline
170 posts
since Aug 2008
Sep 1st, 2008
0

Re: AutoNumber still a problem !! can ne1 clear the mess?

getconnect() is Function to connect to sqlserver.
put this code in module. my module named Koneksi
vb.net Syntax (Toggle Plain Text)
  1. 'In Module
  2. 'Declare outside of class
  3. Imports System.Data
  4. Imports System.Data.SqlClient
  5.  
  6. Module Koneksi
  7. Public conn As SqlConnection
  8. Public Function GetConnect()
  9. conn = New SqlConnection("server = MyServerName;database = MyDatabaseName;Trusted_Connection = yes")
  10. Return conn
  11. End Function
  12. End Module
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,135 posts
since Nov 2007
Sep 2nd, 2008
0

Re: AutoNumber still a problem !! can ne1 clear the mess?

IS THIS CODE WORKING FOR U ???
THOUGH I AM NOT GETTING ANY ERROR NOW IN THE CODE, WHEN I RUN I GET ID AS 1 IN MY ID BOX , HOWEVER , WHEN I INSERT A RECORD , THEN THE NUMBER IS NOT INCREMENTED TO NEXT RECORD....EVEN IF I LOAD MY FORM AGAIN I SHOULD GET TO SEE THE NEXT NUMBER BUT IT STARTS AGAIN FROM 1, THAT VIOLATES MY PRIMARY CONSTRAINT.......WHTS THE PROBL ????

I AM NOT UNDERSTANDING WHY THE AUTO GENERATE FACTOR IS GETTING SO LONG TO BE SOLVED AT MY END.....PLZ CLARIFY SOON !

AWATING RESPONSE

Click to Expand / Collapse  Quote originally posted by Jx_Man ...
getconnect() is Function to connect to sqlserver.
put this code in module. my module named Koneksi
vb.net Syntax (Toggle Plain Text)
  1. 'In Module
  2. 'Declare outside of class
  3. Imports System.Data
  4. Imports System.Data.SqlClient
  5.  
  6. Module Koneksi
  7. Public conn As SqlConnection
  8. Public Function GetConnect()
  9. conn = New SqlConnection("server = MyServerName;database = MyDatabaseName;Trusted_Connection = yes")
  10. Return conn
  11. End Function
  12. End Module
Reputation Points: 10
Solved Threads: 2
Junior Poster
laghaterohan is offline Offline
170 posts
since Aug 2008
Sep 2nd, 2008
0

Re: AutoNumber still a problem !! can ne1 clear the mess?

>> IS THIS CODE WORKING FOR U ???
Yes...Its working for me.

>> WHEN I INSERT A RECORD , THEN THE NUMBER IS NOT INCREMENTED TO NEXT RECORD
Call that procedure after inserting data

>> EVEN IF I LOAD MY FORM AGAIN I SHOULD GET TO SEE THE NEXT NUMBER BUT IT STARTS AGAIN FROM 1, THAT VIOLATES MY PRIMARY CONSTRAINT
Check your database. If your data was inserted then it should working.

And please don't use capital letters. I am trying to help you.
Last edited by Jx_Man; Sep 2nd, 2008 at 6:05 am.
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,135 posts
since Nov 2007
Sep 2nd, 2008
-1

Re: AutoNumber still a problem !! can ne1 clear the mess?

thanks a lot buddy ! problem is solved

Click to Expand / Collapse  Quote originally posted by Jx_Man ...
>> IS THIS CODE WORKING FOR U ???
Yes...Its working for me.

>> WHEN I INSERT A RECORD , THEN THE NUMBER IS NOT INCREMENTED TO NEXT RECORD
Call that procedure after inserting data

>> EVEN IF I LOAD MY FORM AGAIN I SHOULD GET TO SEE THE NEXT NUMBER BUT IT STARTS AGAIN FROM 1, THAT VIOLATES MY PRIMARY CONSTRAINT
Check your database. If your data was inserted then it should working.

And please don't use capital letters. I am trying to help you.
Reputation Points: 10
Solved Threads: 2
Junior Poster
laghaterohan is offline Offline
170 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in VB.NET Forum Timeline: Start Sub in 5 seconds
Next Thread in VB.NET Forum Timeline: Code error.....plz rectify me :)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC