vbturbo
asked on
How to cast/convert a datatablecolumn to string ?
How to cast/convert a datatablecolumn to string ?
["import_policeid"]is a typeof integer
parentView.Table.Columns["
throws this exception
Property Expression can not be used , because there is a cirkular reference in the expression
Thanks
Table.Columns["Import_poli ceID"].ToS tring() should do the job.
Another way to do it is to use the Convert class. It is a class that contains static methods that will convert any object to the requested type (it throws an exception if the type is incompatible, i.e. convert int to date).
So to convert 'import_policeid' to string you would do this:
string strImportPoliceId=Convert. ToString(p arentView. Table.Rows [rowNum][" import_pol iceid"]);
So to convert 'import_policeid' to string you would do this:
string strImportPoliceId=Convert.
ASKER
MogalManic:
The reason i want convert the ["import_policeid"] to string is that i need to apply a row filter on a column which datatype is integer.
.RowFilter = "import_policeid Like '%" & txtsearch.Text & "%'"
and i cannot use the LIKE operator on a column that is type of int.
bungHoc:
Your line states that " Value type of string cannot be converted to a dataview
The reason i want convert the ["import_policeid"] to string is that i need to apply a row filter on a column which datatype is integer.
.RowFilter = "import_policeid Like '%" & txtsearch.Text & "%'"
and i cannot use the LIKE operator on a column that is type of int.
bungHoc:
Your line states that " Value type of string cannot be converted to a dataview
Okay.. thought you just need to convert the entire column to string. But if what you needed is to convert it then import back to DataTable that line won't work.
From top of my head, this is the way to set DataColumn's datatype:
Table.Columns["Import_Poli ceID"].Dat aType = System.Type.GetType("Syste m.String") ;
If it doesn't work let me know, get back to you in a couple of hours when I get back to my workstation with a running C#.
From top of my head, this is the way to set DataColumn's datatype:
Table.Columns["Import_Poli
If it doesn't work let me know, get back to you in a couple of hours when I get back to my workstation with a running C#.
ASKER
bungHoc:
It Throws the following exception:
Datatype for a column can not be altered when the column contains data.
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="C onvert(tot al, 'System.Int32')"
Thanks
It Throws the following exception:
Datatype for a column can not be altered when the column contains data.
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="C
Thanks
Hi vbturbo,
I am sure that you have already thought of this, but if the column is an integer value and you want to filter by number, can you use greater than or less than:
objDS.RowFilter = "import_policeid > 50"
I have not tried this, so I may be out-to-lunch
John
I am sure that you have already thought of this, but if the column is an integer value and you want to filter by number, can you use greater than or less than:
objDS.RowFilter = "import_policeid > 50"
I have not tried this, so I may be out-to-lunch
John
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
MogalManic:
That did it
Thanks to all for colaborating
That did it
Thanks to all for colaborating