[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

ADDING A CALCULATED COLUMS TO A DATATABLE

DENTONE

5/8/2008 8:50:00 AM

Hello,

I have writed this code to file a dataset table with data from a sql table
Dim connstring As String = "Data Source=serverhacpack;Initial
Catalog=master;User ID=HACPACK;Password=francesca"

Dim conn As New SqlConnection((connstring))

conn.Open()

Dim dataSet1 As New DataSet("MERCI")

Dim dataAdapter As New SqlDataAdapter()

dataAdapter.SelectCommand = New SqlCommand("SELECT
[SIGLACONT],[sostanza],[ONU],[CLASSE1],[PG],[NETTOCONT],[N_COLLI],[EMS],[flag]
FROM " + tableName + " Where ([NAVE]='" + Session("nave") + "' AND
[IDVIAGGIO]='" + Session("id") + "')", conn)

dataAdapter.Fill(dataSet1, "MERCI")

dataSet1.Tables(0).Columns.Add("TIPO") ' adding the column TIPO

Return dataSet1.Tables(0)



I have added a column to the table (TIPO) now i want that this column was a
calculeted column , i want that :

-if the filed flag is 0 the TIPO colums become "TRANSITO"

-if the filed flag is 1 the TIPO colums become "IMBARCO"

-if the filed flag is 2 the TIPO colums become "SBARCO"



Thank's for the Help


1 Answer

v-wywang

5/8/2008 10:09:00 AM

0

Hello Dinodentone,

DataColumn.Expression Property doesn't support ICase() Function. But I
believe we can count on IIF().
Please try the following method, and let me know if this is what you need.

//IIF(flag=0,'TRANSITO',IIF(flag=1,'IMBARCO',IIF(flag=2,'SBARCO','Others')))
dataSet1.Tables(0).Columns.Add("t1", typeof(String),
"IIF(flag=0,'TRANSITO',IIF(flag=1,'IMBARCO',IIF(flag=2,'SBARCO','Others')))"
);

For more detailed information about Expression supported on ADO.net 2.0,
please refer to
http://msdn2.microsoft.com/en-us/library/system.data.datacolumn.ex...
spx
[DataColumn.Expression Property]

Hope this helps. Please feel free to let us know if there is anything
unclear. We are glad to assist you.
Best regards,
Wen Yuan

Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/de....
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.