โดย Error ว่า Object reference not set to an instance of an object.
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=pschHRM
StackTrace:
at pschHRM.frmReportSalary.btnSearch_Click(Object sender, EventArgs e) in C:\Users\prh4ck.CIS\Documents\Visual Studio 2010\Projects\pschHRM\pschHRM\frmReportSalary.vb:line 51
at System.Windows.Forms.Control.OnClick(EventArgs e)
at DevComponents.DotNetBar.ButtonX.OnClick(EventArgs e)
at DevComponents.DotNetBar.ButtonX.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at DevComponents.DotNetBar.PopupItemControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at pschHRM.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Code (VB.NET)
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim dtAdapter As New SqlDataAdapter
Dim ds As New DataSet
Dim dt As DataTable
Dim strConnString, strSQL As String
strConnString = "Data Source=.\SQLEXPRESS;Initial Catalog=PSCHHRM;Integrated Security=True"
sb.Append(" SELECT a.HumanID,a.FullName, ") ' Error บรรทัดนี้ครับ
sb.Append(" b.PositionName,c.DatePaid,c.NetEarn,c.NetFee,c.NetPaid ")
sb.Append(" FROM Human a ")
sb.Append(" LEFT JOIN Position b ON a.PositionID = b.PositionID ")
sb.Append(" LEFT JOIN audit c ON a.HumanID = c.HumanID ")
sb.Append(" WHERE a.CustomerID = '" & Me.TextBox1.Text & "' ")
strSQL = sb.ToString
objConn.ConnectionString = strConnString
With objCmd
.Parameters.Clear()
.CommandText = strSQL
.CommandType = CommandType.Text
.Connection = objConn
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds, "ReportSalary")
dt = ds.Tables(0)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Dim rpt As New ReportDocument()
Dim directory As String = My.Application.Info.DirectoryPath
rpt.Load("C:\Users\prh4ck.CIS\Documents\Visual Studio 2010\Projects\pschHRM\pschHRM\crSalary.rpt")
rpt.SetDataSource(dt)
Me.CrystalReportViewer1.ReportSource = rpt
Me.CrystalReportViewer1.Refresh()
End Sub
Tag : .NET, Ms SQL Server 2008, VS 2010 (.NET 4.x)