Solved

Conversion from string "Timeofday" to type 'Integer' is not valid.

Posted on 2012-12-31
6
640 Views
Last Modified: 2013-01-18
Conversion from string "Timeofday" to type 'Integer' is not valid.

 dvholidays = New DataView(dtholidays, "Date = '" & CDate(e.Day.Date) & "' and Username = 'Perkinsj'", "", DataViewRowState.CurrentRows)

            If dvholidays.Item("Timeofday").ToString IsNot "" Then
                Dim iamoff As String = dvholidays.Item("Timeofday").ToString
                '  Dim iamoff As String = dateallreadybooked.havei(e.Day.Date, "Perkinsj")
                Select Case iamoff
                    Case "Am"
                        am.ImageUrl = "Images/Dark_Blue_Button.jpg"
                        am.Enabled = True ' enable the button so the user can change this if they no longer want the day booked
                    Case "Pm"
                        pm.ImageUrl = "Images/Dark_Blue_Button.jpg"
                        pm.Enabled = True ' enable the button so the user can change this if they no longer want the day booked
                    Case "full"
                        full.ImageUrl = "Images/Dark_Blue_Buttonlarge.jpg"
                        full.Enabled = True ' enable the button so the user can change this if they no longer want the day booked
                End Select
            End If

Open in new window

0
Comment
Question by:runnerjp2005
6 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38732372
instade of this dvholidays.Item("Timeofday").
You need to specify the row for which you want to get the value.

like

For Each myDRV In myView
    For i = 0 To myView.Table.Columns.Count - 1
      Console.Write(myDRV(i) & vbTab)
    Next
    Console.WriteLine()
  Next

refer
http://msdn.microsoft.com/en-us/library/23a0aths(v=vs.71).aspx
0
 

Author Comment

by:runnerjp2005
ID: 38732375
dvholidays should reutn 1 row or null anyway
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38732387
then you can save reukt in string variable
Dim myDRV As DataRowView
Dim timeofday As String
timeofday = ""
For Each myDRV In dvholidays
    For i = 0 To myView.Table.Columns.Count - 1
      timeofday = myDRV(i)
    Next
   Next
then work on this variable

if you know exact column number , use that
For Each myDRV In dvholidays
          timeofday = myDRV(1)
     Next
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38732427
There is no overload of the Item property that takes a string (i.e. column name) as its parameter. You have to index by column position.

e.g.

If dvholidays.Item(0).ToString IsNot "" Then

Open in new window


Also, the IsNot should be a <> instead.

If dvholidays.Item(0).ToString <> "" Then

Open in new window

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38733570
@kaufmed

>There is no overload of the Item property that takes a string (i.e. column name)

Sure?

http://msdn.microsoft.com/en-us/library/0k5w061k.aspx

>If dvholidays.Item(0).ToString IsNot "" Then
That would be

If dvholidays.Item(0).Item(0).ToString IsNot "" Then

right? (sorry could not resist)



@runnerjp2005

Change this

If dvholidays.Item("Timeofday").ToString IsNot "" Then

to

If dvholidays.Item(0).Item("Timeofday").ToString IsNot "" Then


The syntax is

DataView.Item(ROWINDEX).Item(COLUMNINDEX or COLUMNNAME)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38733606
@CodeCruiser

Thanks, I thought there was, but I couldn't find it for some reason when I searched. I must have found dated documentation, or something.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now