Question How To Select Curent Date data into Datagrid

dimarzhio

New member
Joined
May 9, 2012
Messages
2
Location
Jakarta
Programming Experience
Beginner
Need Help, I try to select my data from DatePicker value but doesnt work
:stung:
VB.NET:
Public Class DATAG
    Dim SQL As String
    Dim Proses As New CONN
    Dim TBDATA As New DataTable
    'this is my form
    Private Sub DATAG_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Format(DTPICK.Value, "DD/MM/YYYY")
        TBDATA = Proses.ExecuteQuery("SELECT * FROM TRANS_OVER =('" & DTPICK.Text & "')ORDER BY RECID DESC")
  'this is my data grid view     
        DGOT.DataSource = TBDATA
        DGOT.Columns(0).Visible = False
        DGOT.Columns(1).Width = 150
   
 End Sub
 
First, define "doesn't work". Second, what database are you using and what date format does it expect in SQL code? Third, this line of code is completely useless:
VB.NET:
Format(DTPICK.Value, "DD/MM/YYYY")
Forth, have you actually looked at the SQL code you're executing? Finally, you should avoid using string concatenation to insert values into SQL code and do it the proper way instead, i.e. using parameters. If your DAL doesn't support passing parameters then your DAL needs some work. Here are links to blog posts of mine that show how to use parameters and how to incorporate their use into a DAL:

John McIlhinney's .NET Developer Blog: Using Parameters in ADO.NET
John McIlhinney's .NET Developer Blog: Database-independent Data Access Layer
 
First, define "doesn't work". Second, what database are you using and what date format does it expect in SQL code? Third, this line of code is completely useless:
VB.NET:
Format(DTPICK.Value, "DD/MM/YYYY")
Forth, have you actually looked at the SQL code you're executing? Finally, you should avoid using string concatenation to insert values into SQL code and do it the proper way instead, i.e. using parameters. If your DAL doesn't support passing parameters then your DAL needs some work. Here are links to blog posts of mine that show how to use parameters and how to incorporate their use into a DAL:

John McIlhinney's .NET Developer Blog: Using Parameters in ADO.NET
John McIlhinney's .NET Developer Blog: Database-independent Data Access Layer

OMG my SQL syntax does not use "WHERE" condition..:miserable:

VB.NET:
TBDATA = Proses.ExecuteQuery("SELECT * FROM TRANS_OVER =('" & DTPICK.Text & "')ORDER BY RECID DESC")
 
Last edited:
Back
Top