Imports System.Data
Imports System.Data.DataTable
Imports System.Data.SqlClient.SqlDataReader
Imports System.Web.UI.WebControls.SqlDataSource
Partial Class TestDate
Inherits System.Web.UI.Page
Dim connection As New clsMSSQL
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim datet1 As String
Dim datet2 As String
Dim str As String
str = "select * from tb_receive where LEFT(re_date,4)+SUBSTRING(re_date,4,2)+RIGHT(re_date,2) BETWEEN @date1 AND @date2"
Dim dt As New DataTable()
dt = connection.QueryDataTable(str)
End Sub
End Class
Dim str As String
str = "select * from tb_receive where LEFT(re_date,4)+SUBSTRING(re_date,4,2)+RIGHT(re_date,2) BETWEEN datet1 AND datet2"
Dim dt As New DataTable()
dt = connection.QueryDataTable(str)
GridView1.DataSource = dt
GridView1.DataBind()
แต่มันก็ยังขึ้น error เดิมอะครับ invalid column name datet1 กับ invalid column name datet2
Dim con As New SqlConnection(".............................................")
Dim str As String : str = "select * from tb_receive where LEFT(re_date,4)+SUBSTRING(re_date,4,2)+RIGHT(re_date,2) BETWEEN @datet1 AND @datet2"
Dim cmd As New SqlCommand(str, con)
cmd.Parameters.AddWithValue("@datet1", datet1)
cmd.Parameters.AddWithValue("@datet2", datet2)
Dim dt As New DataTable()
Dim adt As New SqlDataAdapter(cmd)
adt.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()