User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 428,374 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,529 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 245 | Replies: 1
Reply
Join Date: Jun 2008
Posts: 19
Reputation: prasadsatam is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
prasadsatam prasadsatam is offline Offline
Newbie Poster

AutoNumberNo

  #1  
Jun 5th, 2008
hi,

Private Sub AutoNumberNo()
try
Dim strsql As String
strsql = "SELECT MAX(Serial_No)+1 FROM Cutting"
Dim com As New SqlCommand(strsql, objconnection)
txtsrno.Text = com.ExecuteScalar() ' result will appear in textbox txtsrno
Catch sqlex As SqlException
MessageBox.Show(sqlex.Message)
End Try
End sub


i try this code but i get following error
1) casting from DBnull to string not possible , when database is empty.
2) serial number increasing from zero, but i want serial number from one
3) serial number not shown in text box.

i am waiting for ur reply........................

prasad satam

mumbai
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Posts: 52
Reputation: bwkeller is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
bwkeller bwkeller is offline Offline
Junior Poster in Training

Re: AutoNumberNo

  #2  
Jun 6th, 2008
First of all you put your code into a code block so that we can read it easier, like so:

visual basic Syntax (Toggle Plain Text)
  1. Private Sub AutoNumberNo()
  2. try
  3. Dim strsql As String
  4. strsql = "SELECT MAX(Serial_No)+1 FROM Cutting"
  5. Dim com As New SqlCommand(strsql, objconnection)
  6. txtsrno.Text = com.ExecuteScalar() ' result will appear in textbox txtsrno
  7. Catch sqlex As SqlException
  8. MessageBox.Show(sqlex.Message)
  9. End Try
  10. End sub

Part of your problem is that you don't allow for a null return, so allow for one:

visual basic Syntax (Toggle Plain Text)
  1. Private Sub AutoNumberNo()
  2. try
  3. Dim strsql As String
  4. strsql = "SELECT IsNull(MAX(Serial_No),0)+1 FROM Cutting"
  5. Dim com As New SqlCommand(strsql, objconnection)
  6. txtsrno.Text = com.ExecuteScalar() ' result will appear in textbox txtsrno
  7. Catch sqlex As SqlException
  8. MessageBox.Show(sqlex.Message)
  9. End Try
  10. End sub
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 7:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC