I have the following form: -
Imports System.Data.SqlClient
-
Public Class Main
-
Protected WithEvents DataGridView1 As DataGridView
-
Dim instForm2 As New Exceptions
-
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startpayrollButton.Click
-
Dim ssql As String = "select MAX(payrolldate) AS [payrolldate], " & _
-
"dateadd(s, 518399, max(payrolldate)) AS [Sunday]" & _
-
"from dbo.payroll" & _
-
" where payrollran = 'no'"
-
Dim oCmd As System.Data.SqlClient.SqlCommand
-
Dim oDr As System.Data.SqlClient.SqlDataReader
-
oCmd = New System.Data.SqlClient.SqlCommand
-
-
Try
-
With oCmd
-
.Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx")
-
.Connection.Open()
-
.CommandType = CommandType.Text
-
.CommandText = ssql
-
oDr = .ExecuteReader()
-
End With
-
If oDr.Read Then
-
payperiodstartdate = oDr.GetDateTime(1)
-
payperiodenddate = payperiodstartdate.AddDays(7)
-
Dim ButtonDialogResult As DialogResult
-
ButtonDialogResult = MessageBox.Show(" The Next Payroll Start Date is: " & payperiodstartdate.ToString() & System.Environment.NewLine & " Through End Date: " & payperiodenddate.ToString())
-
If ButtonDialogResult = Windows.Forms.DialogResult.OK Then
-
exceptionsButton.Enabled = True
-
startpayrollButton.Enabled = False
-
End If
-
End If
-
oDr.Close()
-
oCmd.Connection.Close()
-
Catch ex As Exception
-
MessageBox.Show(ex.Message)
-
oCmd.Connection.Close()
-
End Try
-
-
End Sub
-
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exceptionsButton.Click
-
Dim connection As System.Data.SqlClient.SqlConnection
-
Dim connectionString As String = "Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx"
-
Dim ds As New DataSet
-
Dim _sql As String = "SELECT [Exceptions].Employeenumber,[Exceptions].exceptiondate, [Exceptions].starttime, [exceptions].endtime, [Exceptions].code, datediff(minute, starttime, endtime) as duration INTO scratchpad3" & _
-
" FROM Employees INNER JOIN Exceptions ON [Exceptions].EmployeeNumber = [Exceptions].Employeenumber" & _
-
" where [Exceptions].exceptiondate between @payperiodstartdate and @payperiodenddate" & _
-
" GROUP BY [Exceptions].Employeenumber, [Exceptions].Exceptiondate, [Exceptions].starttime, [exceptions].endtime," & _
-
" [Exceptions].code, [Exceptions].exceptiondate"
-
connection = New SqlConnection(connectionString)
-
Dim _CMD As SqlCommand = New SqlCommand(_sql, connection)
-
Dim adapter As System.Data.SqlClient.SqlDataAdapter
-
adapter.SelectCommand = _CMD
-
_CMD.Parameters.Add(New SqlClient.SqlParameter("@payperiodstartdate", payperiodstartdate))
-
_CMD.Parameters.Add(New SqlClient.SqlParameter("@payperiodenddate", payperiodenddate))
-
Try
-
adapter.Fill(ds)
-
If (ds Is Nothing) Then
-
'it's empty
-
MsgBox("There was no data for this time period, press Ok to continue", "No Data")
-
connection.Close()
-
Exceptions.Hide()
-
Else
-
'it exists and there are rows
-
adapter.Fill(ds)
-
connection.Close()
-
End If
-
-
Catch ex As Exception
-
MessageBox.Show(ex.ToString)
-
connection.Close()
-
End Try
-
Exceptions.Show()
-
End Sub
-
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
-
-
End Sub
-
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
-
End Sub
-
End Class
-
and when I run this with debug, I get to this line: -
adapter.SelectCommand = _CMD
-
and I get the error NullReferenceEx ception was unhandled.
Intellisense warns me that the variable adapter is used before it has been assigned a value. I've tried -
Dim adapter As System.Data.SqlClient.SqlDataAdapter = Nothing
-
and that didn't seem to work either.
Can anyone offer any help with this?
Thank you
0 990 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Terrence |
last post by:
I am doing some of the C# walkthroughs to transition from
VB to C#. When I try to execute
static void Main()
{
Aplication.Run(new Form1())
}
I raise a 'System.NullReferenceException" in
system.windows.forms.dll
|
by: Rafael |
last post by:
Hi, I hope I can find some help for this problem
IDE: Visual Studio.NET 2003 Developer Editio
Language: C#
Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll. Additional information: Object reference not set to an instance of an object.
Visual Studio's IDE is not allowing me to develop projects in C#... I've trying to create a simple Windows Forms project using Visual Studio.NET...
|
by: mike p. |
last post by:
I have a docbook xml file, and am using standard docbook 1.61.3 xsl
stylesheets to do xhtml transform. Transform works fine when using
MSXML.
When I try to do the following using asp.net 1.1:
private void Page_Load(object sender, System.EventArgs e) {
// load content
XslTransform trans = new XslTransform();
|
by: muralidharan |
last post by:
WebForm1.aspx Code:
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI"
Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView
id="TreeView1" Height="520" AutoPostBackOnNodeMove="false"
DragAndDropEnabled="true"
NodeEditingEnabled="False" KeyboardEnabled="true"
CssClass="TreeView" NodeCssClass="TreeNode"
SelectedNodeCssClass="SelectedTreeNode"
HoverNodeCssClass="HoverTreeNode" NodeEditCssClass="NodeEdit"
|
by: David Elliott |
last post by:
I have created an application that will dynamically load other DLLs (plugins).
The new plugin is a winform with an embedded IE Browser.
I am wanting to have the form to run in its own thread. This would allow for other
plugins and the main application to be free to do other work. I have written a
little TestDriver for the plugin and am having some difficulty.
If I don't use threads everything works just fine. If I do use threads, upon...
| |
by: Raed Sawalha |
last post by:
i have a windows form(Main) with listview, when click an item in listview i
open other window form (Sub) which generate the selected item from parent
window in as treeview items when click any item in treeview i display the
content item in axWebBrowser, i close the sub form normally when i close the
main the following error is generated
An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
...
|
by: Chuck Hartman |
last post by:
I have a Windows service that requests web pages from a site using an
HttpWebRequest object. When I try to request a page from an ASP.NET 2 site,
I get a WebException with message "The remote server returned an error:
(500) Internal Server Error." I found a post that suggested to catch the
WebException to retrieve the actual HttpWebResponse object for more
information. The response returned is shown below.
At first I thought this was a...
|
by: sxiao |
last post by:
Hi, there
I got a NullReferenceException when there are more than one users
trying to open the same page at the same time. The senerio is:
Two users logged into the web application using the Windows domain user
account and tried to open the same page which has the databasde query
code. When the two user tried to open the same page at the same time,
there is a runtime error messsage showing as follows:
|
by: Saber |
last post by:
in <system.web> of web.config I've:
<profile>
<properties>
<add name="EnterTime" type="System.DateTime" allowAnonymous="true"/>
</properties>
</profile>
And in Session_Start of global.asax:
|
by: mdhaman |
last post by:
hi,
I have a windows service written in VB.Net and framework 2.0. It is a
multithread service and it is using threadpool to manage threads.
Recently I have started getting NullReferenceException and after that
windows service crashes.
System.Transactions Critical: 0 : <TraceRecord
xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |