Hi Good Guys,
I need your help. Please help me.
I encounter another surprising deadly problem.
I am trying to create a new ProductID and stored it in a variable intProdID and also to display it on the Label.
But I encounter this error message to my surprise:
Object reference not set to an instance of an object
this part of coding generate the error message:
Do While DR.Read
Me.lblProdID.Te xt = DR.Item("NewPro dID") <-Error here
Loop
------------------------------------------
Here are the overall coding
I am very surprise of this error.
Please help me.
Cheers,
Lennie
I need your help. Please help me.
I encounter another surprising deadly problem.
I am trying to create a new ProductID and stored it in a variable intProdID and also to display it on the Label.
But I encounter this error message to my surprise:
Object reference not set to an instance of an object
this part of coding generate the error message:
Do While DR.Read
Me.lblProdID.Te xt = DR.Item("NewPro dID") <-Error here
Loop
------------------------------------------
Here are the overall coding
Code:
Option Explicit On
Imports System.Data.SqlClient
Imports System.Data
Imports System.Drawing
Imports System
'common variable
Dim intProdId As Integer = 0
Private Sub FrmProductMaintain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
FGetNewProductID()
intProdId = Me.lblProdID.Text <---error as well
End Sub
-------------------------------------------------
Private Sub FGetNewProductID()
Dim strSql As String = "Select max(ProductID) + 1 as [NewProdID] from TBLProducts"
try
sqlconn = New SqlConnection(connstr)
sqlconn.Open()
sqlcmd = New SqlCommand(strSql)
sqlcmd.Connection = sqlconn
DR = sqlcmd.ExecuteReader
Do While DR.Read
Me.lblProdID.Text = DR.Item("NewProdID")<--Error here
Loop
DR.Close()
sqlcmd.Dispose()
sqlconn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Please help me.
Cheers,
Lennie
Comment