creating a query in winform app

danait25

New member
Joined
Dec 22, 2011
Messages
3
Programming Experience
1-3
hello,

I'm trying to use a query that is not the "regular" fill / getdata functions that used in tableadapters.
I've creaed a new functions - getdataby(where) and fillby(where)
which gets a "WHERE..." string to add a condition to the regular fill.
I use 3tier application, like this:

In eqsystemDBDataSet.Designer.vb file

VB.NET:
' <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
' Global.System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter"), _
'Global.System.ComponentModel.DataObjectMethodAttribute(Global.System.ComponentModel.DataObjectMethodType.Fill, True)> _
Public Overridable Overloads Function Fillby(ByVal dataTable As eqsystemDBDataSet.WorkersINeventDataTable, ByVal wherexp As String) As Integer
Dim returnValue As Integer
Me.Adapter.SelectCommand = Me.CommandCollection(0)
Try
Me.CommandCollection(0).CommandText += wherexp

If (Me.ClearBeforeFill = True) Then
dataTable.Clear()
End If
returnValue = Me.Adapter.Fill(dataTable)

Return returnValue

Catch ex As Exception

End Try

'Return returnValue
End Function
' <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
' Global.System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter"), _
' Global.System.ComponentModel.DataObjectMethodAttribute
(Global.System.ComponentModel.DataObjectMethodType.[Select], True)> _
Public Overridable Overloads Function GetDataby(ByVal wherexp As String) As eqsystemDBDataSet.WorkersINeventDataTable
Me.Adapter.SelectCommand = Me.CommandCollection(0)
Dim dataTable As eqsystemDBDataSet.WorkersINeventDataTable
dataTable = New eqsystemDBDataSet.WorkersINeventDataTable
Try
Me.CommandCollection(0).CommandText += wherexp
Me.Adapter.Fill(dataTable)

Catch ex As Exception

End Try
Return dataTable
End Function
In Dal project:

VB.NET:
Public Class cldb

Public Function getworkersbydate(ByVal stwhere As String) As eqsystemDBDataSet.WorkersINeventDataTable
Dim CustDa As New eqsystemDBDataSetTableAdapters.WorkersINeventTableAdapter

CustDa.GetDataby(stwhere)

Return CustDa.GetDataby(stwhere)

End Function
End class
In BL project:

VB.NET:
Public Class StoredProcedures
Public Function getworkersbydate(ByVal where As String) As DataTable
Dim custdal As New clDB
custdal.getworkersbydate(where)
Return custdal.getworkersbydate(where)
End Function
End class

In application project:

VB.NET:
Private Sub main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim wherestr As String
wherestr = " WHERE ArrivedWorkers.[xdate] like '%" & Date.Today & "%'"

dt = storedprocedures.getworkersbydate(wherestr)
dgworkers.DataSource = dt

End Sub

MY PROBLEM- when I run the app in debug I see in the Designer.vb file that I get the correct data in the datatable, but when I keep running and go back to the function in the application I get empty datatable.

what can be the problem?

BTW- I tried using the "<global.. etc." that is now in comment but then I can't debug this part and still, the datatable is empty

10x!
 
This isnt how parameterized queries are supposed to work. you're supposed to write the where clause into the sql when going through the adapter wizards ..
Select * From arrivedworkers where xdate like @someDate

call your query FillByDate and call it like: myTA.FillByDate(myDT,"%"&Date.Today&"%")

ie put the % Into the parameter value

your use of appending a where clause suggests you might want to have several different queries (different columns In the where clause) so make a new fillby for each one
 
Back
Top