Search By Date

rex028

Well-known member
Joined
Nov 18, 2004
Messages
50
Programming Experience
Beginner
VB.NET:
Private Sub GetPO()

		Dim fromdate As Date
		fromdate = cboPOsearchTD.Text + "/" + cboPOsearchTM.Text + "/" + cboPOsearchTY.Text
		

		objDS.Clear()
		objDS = objUser.Search_tblUser("Select * from tbl_PURCHASE where Order_Date = 'fromdate'")
	  
		Try
			dgPOSearch.DataSource = objDS.Tables(0)
		Catch ex As Exception

		End Try

	End Sub
I've got a Format Error while execute this function !!

How Come ??
 
Did you do this? : Add a break in your code and step through each line to find which line is giving you the error, and see what your Dim's are set too.

If so which line is causeing the error etc?
 
Error in SearchDataSet Error No. 5 : Format mismatch

VB.NET:
  Private Sub GetPO()
		Dim fromdate As String
		Dim fromday As Date
		fromday = cboPOsearchTD.Text & "/" & cboPOsearchTM.Text & "/" & cboPOsearchTY.Text
		txtPOsearchBranchID.Text = fromday

		If cbSearchAll.Checked Then
			objDS.Clear()
			objDS = objUser.Search_tblUser("Select * from tbl_PURCHASE ")
		Else
			objDS.Clear()
			objDS = objUser.Search_tblUser("Select * from tbl_PURCHASE where Order_Date = '" & fromday & "'")
			Try
				dgPOSearch.DataSource = objDS.Tables(0)
			Catch ex As Exception
			End Try
		End If
	End Sub
VB.NET:
 Public Function Search_tblUser(ByVal strSQL As String) As DataSet
		Try
			Search_tblUser = objDataAdapter.SearchDataSet(strSQL)
		Catch ex As Exception
		End Try
	End Function

VB.NET:
   Public Function SearchDataSet(ByVal strSQL As String) As DataSet
		SetConnectString()
		'Initialize DataAdapter with SQL and connection string
		mobjDA = New OleDb.OleDbDataAdapter(strSQL, strConnect)
		mobjCB = New OleDb.OleDbCommandBuilder(mobjDA)
		objDS.Clear()
 
		'Fill in DataSet
		Try
			mobjDA.Fill(objDS)
			SearchDataSet = objDS 'Return dataset
		Catch ex As Exception
			str = "Error in SearchDataSet. Error No. " & Err.Number & " : " & Err.Description
			GetErrorMessage(str)
			Exit Function
		End Try
	End Function
 
Dates often need to be enclosed in pound signs (#). Try changing this line:
VB.NET:
objDS = objUser.Search_tblUser("Select * from tbl_PURCHASE where Order_Date = '" & fromday & "'")
To this:
VB.NET:
objDS = objUser.Search_tblUser("Select * from tbl_PURCHASE where Order_Date = #" & fromday & "#")
 
COOL !!! it works ~
Thanks alot Paszt !!!
can i kiss you ????? *KISSED* !!!
thanks a LOT !!!
I LOVE YOU MAN!!!!!!!!!!!! *0*
 
i got another problem in this again ...

when i search 15/12/2004 ... it can shows the Record that match it ...

but when i search 9/12/2004 it shows nothing ...

i think the problem is 09/12/2004 ... but even i add "0" in the day ... it still dun work ...
 
Back
Top