•
•
•
•
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
![]() |
•
•
Join Date: Jun 2008
Posts: 19
Reputation:
Rep Power: 1
Solved Threads: 0
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
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
•
•
Join Date: Feb 2008
Posts: 52
Reputation:
Rep Power: 1
Solved Threads: 6
First of all you put your code into a code block so that we can read it easier, like so:
Part of your problem is that you don't allow for a null return, so allow for one:
visual basic Syntax (Toggle Plain Text)
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
Part of your problem is that you don't allow for a null return, so allow for one:
visual basic Syntax (Toggle Plain Text)
Private Sub AutoNumberNo() try Dim strsql As String strsql = "SELECT IsNull(MAX(Serial_No),0)+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
![]() |
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the VB.NET Forum
- Previous Thread: TreeView Adding Children VB 2008
- Next Thread: Compiling Questions


Linear Mode