Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > SQL DateTimePicker
 

SQL DateTimePicker

Hi,

I'm using a DataGridView that's bound to a DataSource, I didn't put in the code directly, I dragged a table from a dataset in the "DATA SOURCES" window and the code was created for me...
I can't see the SQL statement in the code I have to "EDIT THE DATASET WITH DESIGNER" in order to view the statement.
I'd like to have 2 dataTimePicker controls to use as an interval in the SQL statement, but because the SQL statement is not in the code, I don't know how I can refer and change the statement from my code window so that I can use the interval (from dateTimepicker1 to DateTimepicker2) in the SQL Statement,

can anyone help me determine how I can do this?
I greatly appreciate your help!
CapoP  Thursday, January 03, 2008 2:53 PM

Hi CapoP,

Welcome to MSDN forums!

You can hard-code in SelectCommand property of TableAdapter objectthrough Design Viewer.

e.g.

SELECT username, [password], age, isAdmin
FROMUsers
WHERE (username = 'ming') ' hard-code 'ming'

Here is the illustration:

"use the interval (from dateTimepicker1 to DateTimepicker2) in the SQL Statement,"

-> If you wish to add a variable to the SQL Statement, suggest using code instead of Design Viewer Wizard.

Code Block

Imports System.Data.OleDb

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim interval As Int32 = (DateTimePicker2.Value - DateTimePicker1.Value).Days

Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=E:\VBProject\myDB.mdb")

Dim cmd As OleDbCommand = New OleDbCommand("Select * From UserTable Where IntervalColumn < '%" & interval & "%' ", con)

con.Open()

Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)

Dim myDataSet As DataSet = New DataSet()

myDA.Fill(myDataSet, "MyTable")

DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView

End Sub

End Class

Regards,

Martin

Martin Xie - MSFT  Wednesday, January 09, 2008 8:54 AM

Hi CapoP,

Welcome to MSDN forums!

You can hard-code in SelectCommand property of TableAdapter objectthrough Design Viewer.

e.g.

SELECT username, [password], age, isAdmin
FROMUsers
WHERE (username = 'ming') ' hard-code 'ming'

Here is the illustration:

"use the interval (from dateTimepicker1 to DateTimepicker2) in the SQL Statement,"

-> If you wish to add a variable to the SQL Statement, suggest using code instead of Design Viewer Wizard.

Code Block

Imports System.Data.OleDb

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim interval As Int32 = (DateTimePicker2.Value - DateTimePicker1.Value).Days

Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=E:\VBProject\myDB.mdb")

Dim cmd As OleDbCommand = New OleDbCommand("Select * From UserTable Where IntervalColumn < '%" & interval & "%' ", con)

con.Open()

Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)

Dim myDataSet As DataSet = New DataSet()

myDA.Fill(myDataSet, "MyTable")

DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView

End Sub

End Class

Regards,

Martin

Martin Xie - MSFT  Wednesday, January 09, 2008 8:54 AM

You can use google to search for other answers

Custom Search

More Threads

• I think I need an Operator overload for conversion from Object
• Highlight the Row in listview control
• Visual Basic .NET TrippleDES File Encryption
• Microsoft Access, Visual Basic 2008
• Question re: WinAPI and VB.NET
• Exposed Connection String???
• Can't remove AccessRule of Directory Security
• What does 'Repaint a control' mean?
• How to Protect an area of code
• NullReferenceException when using DirectCast