Wrox Programmer Forums
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 5th, 2004, 03:44 AM
Authorized User
 
Join Date: Apr 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to kekohchaa
Default Datagrid

Hi,
I need to display calculation values on the datagrid but the problem is how do I control the datagrid if data in S1 field is =0
If its 0 this msg will come out :->divide by zero error encountered
 Sub BindGrid()
        BindDataSet()
        DataGrid1.Visible = True

        DataGrid1.DataSource = dv
        With DataGrid1
            Try
                DataGrid1.DataBind()
            Catch
                .CurrentPageIndex = 0
                DataGrid1.DataBind()
            End Try
        End With
    End Sub

Sub BindDataSet()
        Dim Area_sf, PSF, L_Area, Price As Double
        objConn = New SqlConnection(ConfigurationSettings.AppSettings("c onnVIOS"))
        strSql = "SELECT *, L_AREA / 0.0929AS Area_sf ,PRICE/(L_AREA / 0.0929) * S2/S1 AS PSF FROM VSALES2"

        sda = New SqlDataAdapter(strSql, objConn)
        ds = New DataSet
        sda.Fill(ds, "Sales")
        dt = ds.Tables("Sales")
        dv = New DataView(dt)
        lblAyat.Text = "Record Found - " & dv.Count
        objConn.Close()

    End Sub


Please help and thanks in advance.


 
Old July 5th, 2004, 02:25 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

replace the line
strSql = "SELECT *, L_AREA / 0.0929AS Area_sf ,PRICE/(L_AREA / 0.0929) * S2/S1 AS PSF FROM VSALES2"

by line using case

strSql = "SELECT *
,L_AREA / 0.0929AS Area_sf
,case S1 when 0 then [Any Max Value] else PRICE/(L_AREA / 0.0929) * S2/S1 end AS PSF
FROM VSALES2"




Ahmed Ali
Software Developer
 
Old July 7th, 2004, 04:13 AM
Authorized User
 
Join Date: Apr 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to kekohchaa
Default

Still not working ahmed any other suggestion?

 
Old July 7th, 2004, 05:41 AM
Registered User
 
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try putting a (If/else) check in place of the strsql= line to make sure s1 isn't 0.. Make a SQLDataReader to check what S1 is, and if it's 0, I'm not sure what that sql line is computing but factor that in however it should be and set it to strsql (need to know what S1 is, and why it would be 0 if it's the denominator), else, put what you have now in strsql.

Btw when you did Ahmed's suggestion, did you write a number in place of [Any Max Value]?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom paging in Datagrid with datagrid page count madhusrp ASP.NET 1.0 and 1.1 Professional 12 June 2nd, 2008 01:15 PM
User COntrol Datagrid inside datagrid rodmcleay ASP.NET 1.0 and 1.1 Professional 3 April 14th, 2007 10:11 AM
Creating DataGrid In Repeater/DataGrid liduwan ASP.NET 1.0 and 1.1 Professional 9 March 6th, 2007 03:31 PM
datagrid ajaidass ADO.NET 2 March 1st, 2007 05:36 PM
Need help regarding datagrid ngsharmila .NET Framework 1.x 1 February 1st, 2006 12:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.