Value of type 'Integer' cannot be converted to 'Double'

 Hi,

     I'm getting this error on my paging class "Value of type 'Integer' cannot be converted to 'Double'." Sad   

--error in bold--

PaginatedList.vb

Public Class PaginatedList(Of T)
    Inherits List(Of T)
    Private _PageIndex As Integer

    Public Property PageIndex() As Integer
        Get
            Return _PageIndex
        End Get
        Private Set(ByVal value As Integer)
            _PageIndex = value
        End Set
    End Property

    Private _PageSize As Integer
    Public Property PageSize() As Integer
        Get
            Return _PageSize
        End Get
        Private Set(ByVal value As Integer)
            _PageSize = value
        End Set

    End Property

    Private _TotalCount As Integer
    Public Property TotalCount() As Integer
        Get
            Return _TotalCount
        End Get
        Private Set(ByVal value As Integer)
            _TotalCount = value
        End Set
    End Property

    Private _TotalPages As Integer
    Public Property TotalPages() As Integer
        Get
            Return _TotalPages
        End Get
        Private Set(ByVal value As Integer)
            _TotalPages = value
        End Set
    End Property

    Public Sub New(ByVal source As IQueryable(Of T), ByVal pageIndex As Integer, ByVal pageSize As Integer)
        pageIndex = pageIndex
        pageSize = pageSize
        TotalCount = source.Count()

        TotalPages = DirectCast(Math.Ceiling(TotalCount / DirectCast(pageSize, Double)), Integer)
        Me.AddRange(source.Skip(pageIndex * pageSize).Take(pageSize))
    End Sub
End Class

 

best regards,

imperialx

0
imperialx
3/25/2009 4:58:17 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

2 Replies
898 Views

Similar Articles

[PageSpeed] 56

Hi imperialx,

Have you thought about using CInt instead of a DirectCast?  I'm not too sure what the difference is between them but it may help.

Try splitting the two functions apart and assigning the value to a variable before you try to cast it.

Hope this helps.


Happy Coding,

SyntaxC4

*** REMINDER ***
If you find this post useful, Please click the 'Mark as Answer' Button.

*** DISCLAIMER ***
All Code is provided AS IS.

** Want Some Useful Sites **

http://www.delicious.com/SyntaxC4
0
SyntaxC4
3/25/2009 7:32:15 AM

SyntaxC4:

Have you thought about using CInt instead of a DirectCast? ...

 

You made my day! Thanks a lot!

TotalPages = CInt(Math.Ceiling(TotalCount / CDbl(pageSize)))

0
imperialx
3/25/2009 8:38:27 AM
Reply:

Similar Artilces:

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

Value of type 'System.Array' cannot be converted to 'Integer'
 Hi,I have a C# code sample that I ran through a C#-to-VB converter, and now Visual Studio gives me the following error for Line 3 of the VB code (Line 6 of the C# code) below:Value of type 'System.Array' cannot be converted to 'Integer'I'm new to VB and C# and could not figure out how to correct this. How can I modify the VB code so that it doesn't give this error? --------------------------- Original Sample ------------------------------- 1 public static class DataSources2 {3 public static StatusCode[] GetHttpStatusCodes()4 ...

table_info('','','','%') cannot return any types
I was recently confirming table_info special cases and discovered the case for getting table_types cannot work. table_info('','','','%') should return a list of table types but it returns a list of empty strings instead: my @types = $h->tables('', '', '', '%'); print "all types:\n", join("xxx\n", @types), "\n"; # should output something like: # "dbo" # "INFORMATION_SCHEMA" # "sys" # and actually outputs: xxx xxx It seems to be down to the following ...

Cannot convert type 'type' to 'type'
I am learning all of this, so I am still fresh, so please bear with me :)I have a page that has some txtboxes in it, simple registration form, and I have a button that will save those txt boxes to the db. I am using:- I am using Visual Web Developer 2008 Express Edition- C# When I try to compile the project I get error: Cannot convert type 'System.Web.UI.WebControls' to 'String' This is content of my web.config    <profile> <properties> <add name="FirstName"/> <add name="LasttName"/>...

value of type 'XXX' cannot be converted to type 'XXX'
 I've had this issue with VS2008 lately that is driving me crazy.  I have a website where I built a class that does all my Web Service interaction.  This class returns instances of Web Service proxies, or list of the same.  In my web page I'll create a temporary variable (Dim - I'm using VB) with the same type that my service class is going to return.  When I assign my variable to the return of the method, I'm getting a message similar to the following"Value of type 'Namespace.Foo' cannot be converted to type 'Namespace.Foo'. ...

Value of type 'System.Net.Mail.MailMessage' cannot be converted to 'System.Net.Mail.AlternateView'
Trying to create an alternateview to send a txt email with the html formatted email.  I've used string builder to create the whole email, but I get this error.  Any ideas why?  i've bolded the line that throws the error... Dim EmailBodyTxt As New StringBuilder EmailBodyTxt.Append("<html><style type='text/css'>.table{border:solid; border-color:#006666; width:600;} ")EmailBodyTxt.Append("<body><table class='table'><tr><td colspan='2'><h1>Test<br />RESPONSE SYSTEM</h1></td>...

Value of type 'String' cannot be converted to 'System.Net.Mail.MailAddress'
My code is below:Protected Sub btnSendMsg_OnClick(ByVal Source As Object, ByVal E As EventArgs) Dim myMessage As New System.Net.Mail.MailMessage Dim myAttachment As System.Net.Mail.Attachment Dim myMail As System.Net.Mail.SmtpClient If Page.IsValid() Then myMessage.From = txtFromEmail.Text myMessage.To = txtToEmail.TextWhat can I do to fix this? MailMessage.To represents a collection that you Add addresses to.Dim recipient As MailAddress= new MailAddress(txtToEmail.Text) myMessage.To.Add(recipient)    Mike Banavige~~~~~~~~~~...

Value of type 'Integer' cannot be converted to 'System.Data.SqlClient.SqlDataReader'
Value of type 'Integer' cannot be converted to 'System.Data.SqlClient.SqlDataReader' I get the above error when I try to do this code: Dim dr As SqlDataReaderDim ID As Integer dr = oDeveloper.GetDeveloper(CllrID) anyone any ideas around this? macca   well obviously, GetDeveloper Takes a DataReader What do you mean Jeffrey? How can I get the values from GetDeveloper to my datareader dr then? macca Enable Strict for your project.  That will tell you exactly what's wrong. I think the error message already says what is wrong.If you haven't got a clue about something don...

Operator '>' is not defined for type 'DBNull' and type 'Integer'.
this is my code I don't get why I'm getting this error SubModel is a number :   Example : 823 If Ds.Tables(0).Rows(0).Item("SubModel") > 0 Then Dim crst As New DataSet SqlStr = "SELECT SubModelName FROM SubModel,AcesData WHERE AcesData.SubModel = SubModel.SubModelID and (SubModelID = ?)" Dim da2 As New Data.OleDb.OleDbDataAdapter(SqlStr, conn) da2.SelectCommand.Parameters.Add("?", Data.OleDb.OleDbType.VarChar).Value = Ds.Tables(0).Rows(0).Item("SubModel")...

'Value' should be between 'minimum' and 'maximum'.
I'm attempting to invoke with parameters:  Dim thing2 As New mydelsubPBStep(AddressOf pbStep) Me.Invoke(thing2, "setMax", dt.Rows.Count)      <---- this is where the error occurs   the delegate looks like this: Private Delegate Sub mydelsubPBStep(ByVal mode As String, ByVal value As Integer)   the function it's calling looks like this:Private Sub pbStep(ByVal mode As String, ByVal value As Integer) Select Case mode.ToLower Case "clear" ProgressBar1.Value = 0 Case "step" ProgressBar1.PerformStep() L...

Value of type 'Integer' cannot converted to 'System.Web.UI.WebControls.Unit'
I'd like to dynamically change the size of controls such as panel.In the code I putmainPage.Height = 500  'mainPage is a PanelHowever, it failed to compile with message;Value of type 'Integer' cannot converted to 'System.Web.UI.WebControls.Unit'How can I change the code so that it compiles? mainPage.Height = Unit.Pixel(500)  'mainPage is a PanelSonu Kapoor [MVP] Feel free to ask me any .NET question | Ajax Data Controls Forum It works very well. Thanks a lot....

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...