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 991 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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |