Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All,

I have a decimal field from SQL filled up by Dataadapter into a temp Datatable.

Now i want the the rows with field greater than or equal to 0 should be shown in 1 datagridview column and the rest (<0) into another column.

Please advice

Thanks in advance.
Posted

1 solution

Try:
SQL
SELECT CASE WHEN field<0 THEN field ELSE 0 END AS Below, CASE WHEN field>=0 THEN field ELSE 0 END AS Above FROM MyTable
 
Share this answer
 
Comments
Maciej Los 14-Feb-14 16:10pm    
+5
atul sharma 5126 14-Feb-14 23:28pm    
Thanks for the reply. But i am not sure where to use your provided code. Below is my sub. pls suggest.

Try
connection.Open()

Dim DA As SqlDataAdapter = New SqlDataAdapter

DA.SelectCommand = New SqlCommand("Select FAVCD,FAVCA from FAVC , connection)


Dim dtAccountStatement As New DataTable

DA.Fill(dtAccountStatement)


grdAccountStatement.AutoGenerateColumns = False
grdAccountStatement.DataSource = dtAccountStatement


For Each row As DataGridViewRow In grdAccountStatement.Rows

grdAccountStatement.Columns(0).DataPropertyName = "FAVCD"


Next

connection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
atul sharma 5126 15-Feb-14 10:16am    
Thanks. Was able to run the sql command
OriginalGriff 15-Feb-14 10:25am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900