Results 1 to 4 of 4

Thread: [RESOLVED] Error "Argument 'Prompt' cannot be converted to type 'String'"

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2016
    Posts
    39

    Resolved [RESOLVED] Error "Argument 'Prompt' cannot be converted to type 'String'"

    hi ti all
    i have the following code


    Code:
      Private Sub FillDGV_AllUnCompited_Lipantika()
            Dim Order_Row1 As DataRow
            Dim date1 As Date
            Dim Condition, supplier, DAs, TPs, temp As String
            Condition = ""
            supplier = ""
            DAs = ""
            TPs = ""
            temp = ""
            Try
                OrdersDataSet.Clear()
                ServisNote_connection.Open()
                cmdstr = "SELECT * FROM Lipantika_Orders WHERE Complited = 'FALSE' ORDER BY EkdosiDate DESC"
                OrdersTableAdapter = New SqlDataAdapter(cmdstr, ServisNote_connection)
                OrdersTableAdapter.Fill(OrdersDataSet, "Orders")
                ServisNote_connection.Close()
            Catch ex As Exception
                ServisNote_connection.Close()
                MsgBox(ex.Message)
            End Try
            If OrdersDataSet.Tables("Orders").Rows.Count = 0 Then
                MessageBox.Show("Δεν υπάρχει καμία μη ολοκληρωμένη παραγγελία λιπαντικών καταχωρημένη", "Ενημέρωση!", MessageBoxButtons.OK, MessageBoxIcon.Information)
                chkAllUncomplited.CheckState = CheckState.Unchecked
                Exit Sub
            End If
            For i = 0 To OrdersDataSet.Tables("Orders").Rows.Count - 1
                Order_Row1 = OrdersDataSet.Tables("Orders").Rows(i)
                date1 = Order_Row1.Item(3)
                'If Order_Row.Item(15) = True Then
                Condition = "ΝΑΙ"
                'Else
                '    Condition = "ΟΧΙ"
                'End If
                'MsgBox(OrdersDataSet.Tables("Orders").Rows(i).Item(9))
                'Try
                MsgBox(OrdersDataSet.Tables("Orders").Rows(i).Item(9))
                'Catch ex As Exception
                '    MessageBox.Show(ex.ToString)
                'End Try
                If Order_Row1.Item(9) <> "-" Then
                    Try
                        DADataSet.Clear()
                        ServisNote_connection.Open()
                        cmdstr = "SELECT * FROM Deltia_Apostolis"
                        DATableAdapter = New SqlDataAdapter(cmdstr, ServisNote_connection)
                        DATableAdapter.Fill(DADataSet, "DAs")
                        ServisNote_connection.Close()
                    Catch ex As Exception
                        ServisNote_connection.Close()
                        MsgBox(ex.Message)
                    End Try
                    temp = Order_Row1.Item(9)
                    If temp.Contains(",") = False Then
                        DACount = 1
                        ReDim DAIDs(DACount - 1)
                        ReDim DANumbers(DACount - 1)
                        DAIDs(0) = temp
                        For j = 0 To DADataSet.Tables("DAs").Rows.Count - 1
                            If DADataSet.Tables("DAs").Rows(j).Item(0) = temp Then
                                DANumbers(0) = DADataSet.Tables("DAs").Rows(j).Item(3)
                            End If
                        Next
                    Else
                        Call Find_DAs(temp, DADataSet, DAs)
                    End If
                    For j = 0 To DACount - 1
                        If j = 0 Then
                            DAs = DANumbers(j)
                        Else
                            DAs = DAs + "," + DANumbers(j)
                        End If
                    Next
                Else
                    DAs = "-"
                End If
                If Order_Row1.Item(10) <> "-" Then
                    Try
                        InvoiceDataSet.Clear()
                        ServisNote_connection.Open()
                        cmdstr = "SELECT * FROM Invoices"
                        InvoiceTableAdapter = New SqlDataAdapter(cmdstr, ServisNote_connection)
                        InvoiceTableAdapter.Fill(InvoiceDataSet, "Invoices")
                        ServisNote_connection.Close()
                    Catch ex As Exception
                        ServisNote_connection.Close()
                        MsgBox(ex.Message)
                    End Try
                    temp = Order_Row1.Item(10)
                    If temp.Contains(",") = False Then
                        TPCount = 1
                        ReDim TPIDs(TPCount - 1)
                        ReDim TPNumbers(TPCount - 1)
                        TPIDs(0) = temp
                        For j = 0 To InvoiceDataSet.Tables("Invoices").Rows.Count - 1
                            If InvoiceDataSet.Tables("Invoices").Rows(j).Item(0) = temp Then
                                TPNumbers(0) = InvoiceDataSet.Tables("Invoices").Rows(j).Item(4)
                            End If
                        Next
                    Else
                        Call Find_TPs(temp, InvoiceDataSet, TPs)
                    End If
                    For j = 0 To TPCount - 1
                        If j = 0 Then
                            TPs = TPNumbers(j)
                        Else
                            TPs = TPs + "," + TPNumbers(j)
                        End If
                    Next
                Else
                    TPs = "-"
                End If
                For j = 0 To SuppliersDataSet.Tables("Suppliers").Rows.Count - 1
                    If SuppliersDataSet.Tables("Suppliers").Rows(j).Item(0) = Order_Row1.Item(1) Then
                        supplier = SuppliersDataSet.Tables("Suppliers").Rows(j).Item(1)
                    End If
                Next
                Dim row As String() = New String() {Order_Row1.Item(0), Order_Row1.Item(2), date1.ToString("dd-MM-yyyy"), Condition, supplier, DAs, TPs}
                DataGridView1.Rows.Add(row)
            Next
            For i = 0 To DataGridView1.Rows.Count - 1
                If DataGridView1.Rows(i).Cells(3).Value = "ΝΑΙ" Then
                    DataGridView1.Rows(i).DefaultCellStyle = New DataGridViewCellStyle With {.BackColor = Color.GreenYellow}
                End If
            Next
        End Sub

    the Design of the table "Lipantika_Orders" (means lubricants orders) in my SQL Database is the following

    Name:  Table1.jpg
Views: 160
Size:  32.4 KB

    and the selected 2 records of that table

    Name:  Table2.jpg
Views: 161
Size:  32.2 KB

    As you see the column 9 named "Related_DA" is type nvarchar(MAX) and have the value of "-" in both 2 records.

    When i run my code, at line MsgBox(OrdersDataSet.Tables("Orders").Rows(i).Item(9))
    i receive the error message "Argument 'Prompt' cannot be converted to type 'String'"

    and if remove that line, at the line If Order_Row1.Item(9) <> "-" Then
    i receive the error message "Operator '<>' is not defined for type 'DBNull' and string "-" "

    can any one help me why i receive those errors ?

    I have no idea, and i google it for 2 hours without any results

    Thanks in advance.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,735

    Re: Error "Argument 'Prompt' cannot be converted to type 'String'"

    Do you really care about the first error? Perhaps not, in the end, so let's focus on the second error. The message in that case tells you the problem, since <> is not defined for DBNull. I suppose it COULD be, since it's pretty clear to us, but it isn't. Therefore, you have to check for DBNull explicitly before you do the comparison. There are a couple ways to do that. What I use is IsDBNull(), so it would look like:
    Code:
    If IsDBNull(Order_Row1.Item(9)) = False AndAlso Order_Row1.Item(9).ToString <> "-" Then
    There is also the IsNullOrEmpty method in String, but that may not be any more efficient.

    Also, you should turn Option Strict ON for the project and fix all the issues. You're doing some odd things with conversions in there. You seem to be taking a DataAdapter and putting it into a variable that looks like it is supposed to hold a TableAdapter. If these are strongly typed datasets, then you have at least one further means of checking for DBNull values. You also don't need to be opening and closing the connection with the DataAdapter, as it will do what it needs to do, and leave the connection in the same state that it found it.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2016
    Posts
    39

    Re: Error "Argument 'Prompt' cannot be converted to type 'String'"

    Thanks for the responce Shaggy Hiker!
    I did the check for DBNull. There is no null value
    for the item(9) (Order_Row1.Item(9)).
    You ca see that in the second picture i send...

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2016
    Posts
    39

    Re: Error "Argument 'Prompt' cannot be converted to type 'String'"

    Again.
    I wrote the statement as you say, and the problem is solved.
    So thank you very much for your suggestion you make.
    I also take in consideration all other you say about
    option statement STRICT, and for opening and closing the connection.
    Thank you again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width