473,811 Members | 3,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Not getting results in datagrid view

347 Contributor
I have two forms and I'm trying to pass a declared variable from form1 to form2 and then pass that variable in a sql query that I have in a dataset that is bound to my form. I know that my query works but it's not producing any data. I have debugged my form and can see the data being passed in the variables elsewhere on the page but I'm not sure of the syntax within the query. Can someone please offer assistance.

My variables are declared in a module:

Expand|Select|Wrap|Line Numbers
  1. Public Module myGlobalVars
  2.     Public payPeriodStartDate As New System.DateTime
  3.     Public payPeriodEndDate As New System.DateTime
  4. End Module
  5.  
and here is form1:
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2.  
  3. Public Class Main
  4.     Dim instForm2 As New Exceptions
  5.     Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startpayrollButton.Click
  6.         Dim ssql As String = "select MAX(payrolldate) AS [payrolldate], " & _
  7.                  "dateadd(dd, ((datediff(dd, '17530107', MAX(payrolldate))/7)*7)+7, '17530107') AS [Sunday]" & _
  8.                   "from dbo.payroll" & _
  9.                   " where payrollran = 'no'"
  10.         Dim oCmd As System.Data.SqlClient.SqlCommand
  11.         Dim oDr As System.Data.SqlClient.SqlDataReader
  12.  
  13.         oCmd = New System.Data.SqlClient.SqlCommand
  14.         Try
  15.             With oCmd
  16.                 .Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=xxxxx;Data Source=xxxxx;uid=xxxxx;password=xxxxx")
  17.                 .Connection.Open()
  18.                 .CommandType = CommandType.Text
  19.                 .CommandText = ssql
  20.                 oDr = .ExecuteReader()
  21.             End With
  22.             If oDr.Read Then
  23.                 payPeriodStartDate = oDr.GetDateTime(1)
  24.                 payPeriodEndDate = payPeriodStartDate.AddDays(7)
  25.                 Dim ButtonDialogResult As DialogResult
  26.                 ButtonDialogResult = MessageBox.Show("      The Next Payroll Start Date is: " & payPeriodStartDate.ToString() & System.Environment.NewLine & "            Through End Date: " & payPeriodEndDate.ToString())
  27.                 If ButtonDialogResult = Windows.Forms.DialogResult.OK Then
  28.  
  29.                     exceptionsButton.Enabled = True
  30.                     startpayrollButton.Enabled = False
  31.  
  32.                 End If
  33.             End If
  34.             oDr.Close()
  35.             oCmd.Connection.Close()
  36.         Catch ex As Exception
  37.             MessageBox.Show(ex.Message)
  38.             oCmd.Connection.Close()
  39.         End Try
  40.  
  41.     End Sub
  42.  
  43.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exceptionsButton.Click
  44.         Exceptions.Show()
  45.     End Sub
  46.  
  47.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  48.         EmployeeEditform.Show()
  49.     End Sub
  50.  
  51.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  52.  
  53.     End Sub
  54. End Class
  55.  
and here is form 2 sql query:
Expand|Select|Wrap|Line Numbers
  1. SELECT Employeenumber, Exceptiondate, Starttime, Endtime,Duration, Code, Submittedby FROM Exceptions   
  2. WHERE [Exceptions].exceptiondate   >= '" & payperiodStartDate &   
  3. "' and [Exceptions].exceptiondate <='" & payPeriodEndDate & "'
  4.  

The sql query works as I've debugged it within the form itself and I can see the correct data being presented, but it's just not showing up in the datagrid view. Any help would be greatly appreciated.

Thank you,

Doug
Jan 3 '11 #1
0 966

Sign in to post your reply or Sign up for a free account.

Similar topics

5
7108
by: ComputerStop | last post by:
I am attempting to print a datagridview. I have not found any method that works successfully. Has any one been successful with this?
2
2297
by: Bob | last post by:
I looked at the sample in the msdn january 2005 - Introducing a new datagrid, but the project downloaded failed to open. Any one can point me to a bit of code on how to go and select an image that will get put in the datagridview. The column is bound to a sql server 2005 image data field. I just need to know how to put the image in the column. Any help appreciated. Bob
0
1207
by: shukyh | last post by:
Hi all I would like to generate an HTML page from datagridview in win application (not webform). In th datagrid view I have DataGridViewCheckBoxColumn columns. How Can i do this? Thanks, Shuky
0
1117
by: Tony A. | last post by:
I'm using VB 2005 with MS Access for as the database. I have a table (tblItem) that has two columns, ItemNum (key field) and ItemDescription. I also have a second table (tblOrdersDetail), this table has two columns ItemNum and ItemDescription Using a Datagrid View that is bound to the tblOrdersDetail table. When a users enters a number in the ItemNum column of the datagrid view I'd like the ItemDescription column of the datagrid view...
1
2594
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
How do I get the value of a checkbox in a row in a datagrid view please? I have tried many methods and nothing workds. This was so much easier in VB 6.0. THanks for any help you can give me.
1
1769
by: radhikabista | last post by:
hey friends , i m not being able to save the updates in datagrid view when i press buttonsave_ gridview i have a class customer with two methods one to get the dataset and other to update database: i dont know what is the problem with my code. i always get UPDATE syntax run time error, as i press button_save_grod view : please help me. my code goes like this: public class customer { // private static string strConn;
1
1538
by: radhikabista | last post by:
i have a table tbl_client in Ms Access database. my program displays a datagrid view with the search result records. i want to save the changes to data gridview to database.for this i call the update method of a class customer to save the changes when user click on update button. every time i run the code i get the run time error datatype mis match error in update statement. my class goes like this: public int update() { ...
1
3834
mafaisal
by: mafaisal | last post by:
Hello Experts I am Using vb.net 2005 Hw To Put DateTime Picker in Datagrid view I have to sea Datetime Picker in Specified Cilomn of Datagrid I try This But The Location Hw To Change to the column location or In DatagridView any Datetime Picker like DataGridViewComboBoxColumn,DataGridViewCheckBoxColumn etc..?
1
1359
by: menyki | last post by:
pls i designed a database application using visual basic. i have done the coding for the print incase i want to print out the data. Pls my problem is how to code at design time for the application to print the data in a tabular form. for now the records prints ontop of each other, i want the records and the field separated by rows and cells of a table as normal. I used Ms access to design the database and the data is displayed by datagrid...
0
1574
by: menyki | last post by:
pls i designed a database application using visual basic. i have done the coding for the print incase i want to print out the data. Pls my problem is how to code at design time for the application to print the data in a tabular form. for now the records prints ontop of each other, i want the records and the field separated by rows and cells of a table as normal. I used Ms access to design the database and the data is displayed by datagrid...
0
9604
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,...
0
10644
Oralloy
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...
0
10379
jinu1996
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...
0
9201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7665
isladogs
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...
0
6882
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();...
1
4336
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
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.