Solved

casting /filtering problem

Posted on 2007-11-26
19
300 Views
Last Modified: 2010-04-23
Hi

Im trying to cast a dataview column to string

Property Expression can not be used , because there is a cirkular reference in the expression

I have the problem filtering a column which is a type of integer use the like operator when passing a txtbox input e.g = 4

how can i address this problem?

vbturbo



parentView.Table.Columns("import_policeid").Expression = "Convert('import_policeid',System.String)"
 

                With parentView

                    .RowFilter = "import_policeid Like '%" & txtsearch.Text & "%' Or xml_kunde_navn Like '%" & txtsearch.Text & "%' Or import_kundenr Like '%" & txtsearch.Text & "%' Or xml_kunde_adresse1 Like '%" & txtsearch.Text & "%' Or import_id Like '%" & txtsearch.Text & "%'"

                    .RowStateFilter = DataViewRowState.CurrentRows

                End With

Open in new window

0
Comment
Question by:vbturbo
  • 10
  • 7
  • 2
19 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20349014
  .RowFilter = "import_policeid Like '%" & txtsearch.Text & "%' Or xml_kunde_navn Like '%" & txtsearch.Text & "%' Or import_kundenr Like '%" & txtsearch.Text & "%' Or xml_kunde_adresse1 Like '%" & txtsearch.Text & "%' Or import_id=" & txtsearch.Text & "%"
                    .RowStateFilter = DataViewRowState.CurrentRows
                End With
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20349018
  .RowFilter = "import_policeid Like '%" & txtsearch.Text & "%' Or xml_kunde_navn Like '%" & txtsearch.Text & "%' Or import_kundenr Like '%" & txtsearch.Text & "%' Or xml_kunde_adresse1 Like '%" & txtsearch.Text & "%' Or import_id=" & txtsearch.Text & ""
                    .RowStateFilter = DataViewRowState.CurrentRows
                End With
0
 
LVL 18

Author Comment

by:vbturbo
ID: 20349038
throws this exception
There is missing an operand after operator 'Mod'.

I need also to be able to use the like operator on import_id =" & txtsearch.Text & "%" instead of the equal operator

thanks

0
 
LVL 18

Author Comment

by:vbturbo
ID: 20349045
your second suggestion throws

Column [s] was not found.
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 100 total points
ID: 20349053

pratima_mcs:
  .RowFilter = "import_policeid Like '%" & txtsearch.Text & "%' Or xml_kunde_navn Like '%" & txtsearch.Text & "%' Or import_kundenr Like '%" & txtsearch.Text & "%' Or xml_kunde_adresse1 Like '%" & txtsearch.Text & "%' Or import_id=" & txtsearch.Text
                    .RowStateFilter = DataViewRowState.CurrentRows
                End With
0
 
LVL 18

Author Comment

by:vbturbo
ID: 20349104
well i have redefined my structure a bit and it works ,but.....

                With parentView
                    If bool = False Then
                        .RowFilter = "" & var & " Like '%" & txtsearch.Text & "%'"
                    Else
                       ' here it shows only the exact match........How do i apply the like operator ????????
                        .RowFilter = "" & var & " = " & txtsearch.Text & ""
                    End If
                    .RowStateFilter = DataViewRowState.CurrentRows
                End With

thanks
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20349111
you can't apply like to int
0
 
LVL 18

Author Comment

by:vbturbo
ID: 20349117
but then how can i cast the  "import_policeid" column to string ?

parentView.Table.Columns("import_policeid").Expression = "Convert('import_policeid',System.String)"

throws
Property Expression can not be used , because there is a cirkular reference in the expression


0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20349193
why you need like for the int ?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 18

Author Comment

by:vbturbo
ID: 20349272
to filter out long invoice numbers.(15-18 digits)

Im just looking for a solution to cast a column to string.
And of course create a overhead by adding a column to the table ,assign the values from the int column
then remove the int column .........ect

that i would like to avoid.

Do you know how to cast/convert a column to string ?
0
 
LVL 18

Author Comment

by:vbturbo
ID: 20349275
sorry correction:

to filter out long invoice numbers.(15-18 digits)

Im just looking for a solution to cast a column to string.
Of course i could create a overhead by adding a column to the table ,assign the values from the int column
then remove the int column .........ect

that i would like to avoid.

Do you know how to cast/convert a column to string ?
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20349346
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20349353
0
 
LVL 18

Author Comment

by:vbturbo
ID: 20349368
at the middle of this page it shows how to convert a datatable column

but where am i dropping the ball ?



https://msdn2.microsoft.com/en-us/library/system.data.datacolumn.expression(VS.71).aspx

The following functions are also supported:

CONVERT

Description Converts given expression to a specified .NET Framework Type.
Syntax Convert(expression, type)
Arguments expression-- The expression to convert.
type-- The .NET Framework type to which the value will be converted.
 

Example: myDataColumn.Expression="Convert(total, 'System.Int32')"
0
 
LVL 34

Accepted Solution

by:
Sancler earned 400 total points
ID: 20352151
>>
Im just looking for a solution to cast a column to string.
Of course i could create a overhead by adding a column to the table ,assign the values from the int column
then remove the int column .........ect
<<

I don't think you can do this - at least using in-built functions - without the overhead: and, if you do that, you won't be able to "remove the int column ..."

The page you are referring to/quoting from is concerned with expression _columns_ (although the same rules also apply to other expressions - e.g. .RowFilters).  Now, when you use it as an expression in a column, the column actually CONTAINS the _expression_, although it will DISPLAY the value that resuts from that application of that expression to the other (relevant) data in the row concerned.  What your original attempt was doing was saying: display in column 'import_policeid' the result of casting the value in column 'import_policeid' as a string.  But that, explained in that way, is obviously a circular reference.  Further - and this is why you won't (with this approach) be able to "remove the int column" - once you remove the referenced column, the expression column has no data remaining to which to apply its formula.

What you might (??) be able to do - given, as I say above, that "expression" rules are the same for rowfilters as for expression columns - is use the CONVERT() function in the rowfilter.  But I haven't tried it (so far as I can recall) myself.

Roger
0
 
LVL 18

Author Comment

by:vbturbo
ID: 20352827
Hi Roger

Sorry for my late responce, just came home from work.

Thanks for an "as always"  competent responce and elaboration.
Glad that you still are around, long time no see -;)

I really miss some of your comments as you seem absent now a days.

Thinking deeper in applying the convert() function in the rowfilter.
Should be possible in the same way as in a SQL select against a datasource where you can cast and convert
Ill do some testing in this regard.

If anything else pops into your mind please drop in with a comment.


Jens
0
 
LVL 18

Author Comment

by:vbturbo
ID: 20352965
Roger

I think this should the trick

parentView.RowFilter = "Convert(import_policeid, 'System.String')  Like '%" & txtsearch.Text & "%'"

ill test it tomorrow and let you know

Jens


0
 
LVL 34

Expert Comment

by:Sancler
ID: 20354133
Jens

I've been, and still am, rather busy on other things.  So although I keep an eye on EE when I can, I'm not contributing so much.  In particular, I try to resist posting where it looks like the thread might get protracted.  But I know that you and I are "on the same wavelength" and  that you'd get the point I was trying to make without me having to put it in half a dozen different ways.  Hence my comment on this.

It looks like it should work.  I'll be interested to hear if it does.

Roger
0
 
LVL 18

Author Comment

by:vbturbo
ID: 20356122
Roger

It works like a charm.

Jens
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now