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

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2008
Posts: 126
Reputation: laghaterohan is an unknown quantity at this point 
Solved Threads: 1
laghaterohan laghaterohan is offline Offline
Junior Poster

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

 
0
  #1
Sep 1st, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

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

 
3
  #2
Sep 1st, 2008
Try This :
  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
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 126
Reputation: laghaterohan is an unknown quantity at this point 
Solved Threads: 1
laghaterohan laghaterohan is offline Offline
Junior Poster

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

 
0
  #3
Sep 1st, 2008
thanks but still getting an error ! can u plz tell which files to import ???



Originally Posted by Jx_Man View Post
Try This :
  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

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

 
0
  #4
Sep 1st, 2008
This some files to import :
  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.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 126
Reputation: laghaterohan is an unknown quantity at this point 
Solved Threads: 1
laghaterohan laghaterohan is offline Offline
Junior Poster

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

 
0
  #5
Sep 1st, 2008
error like getconnect() not defined.....?
[

QUOTE=Jx_Man;682207]This some files to import :
  1. Imports System.Data
  2. Imports System.Data.SqlClient

what kind of error ??[/QUOTE]
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

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

 
0
  #6
Sep 1st, 2008
getconnect() is Function to connect to sqlserver.
put this code in module. my module named Koneksi
  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
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 126
Reputation: laghaterohan is an unknown quantity at this point 
Solved Threads: 1
laghaterohan laghaterohan is offline Offline
Junior Poster

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

 
0
  #7
Sep 2nd, 2008
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

Originally Posted by Jx_Man View Post
getconnect() is Function to connect to sqlserver.
put this code in module. my module named Koneksi
  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

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

 
0
  #8
Sep 2nd, 2008
>> 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.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 126
Reputation: laghaterohan is an unknown quantity at this point 
Solved Threads: 1
laghaterohan laghaterohan is offline Offline
Junior Poster

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

 
0
  #9
Sep 2nd, 2008
thanks a lot buddy ! problem is solved

Originally Posted by Jx_Man View Post
>> 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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC