Приведение строки "0,00 р." к типу "Double" является недопустимым - Visual Basic .NET

Узнай цену своей работы

Формулировка задачи:

при сборке проекта выводится ошибка: Приведение строки "0,00 р." к типу "Double" является недопустимым. подскажите как исправить
Public Class Form1
    Friend cn As OleDb.OleDbConnection
    Friend da As New OleDb.OleDbDataAdapter
    Dim ds As New DataSet
    Dim G_Rec_ID
    Friend Admin As Boolean = False
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Button2.Text = "Добавить" Then
            If NumericUpDown1.Value + NumericUpDown2.Value = 0 Or TextBox1.Text = "" Then
                MsgBox("Не все поля заполнены", MsgBoxStyle.Exclamation)
                Exit Sub
            End If
            Dim InsCommand As New OleDb.OleDbCommand("INSERT INTO Calculate (Товар, Дата, Цена, Остаток) VALUES ('" & TextBox1.Text & "', " & AccDate(Now) & ", '" & NumericUpDown1.Value - NumericUpDown2.Value & "', '" & Label7.Text & "')", cn)
            InsCommand.ExecuteNonQuery()
        Else
            Dim UpdCommand As New OleDb.OleDbCommand("UPDATE [Calculate] SET [Товар]='" & TextBox1.Text & "', [Цена]='" & NumericUpDown1.Value - NumericUpDown2.Value & "' WHERE [Код]=" & G_Rec_ID, cn)
            UpdCommand.ExecuteNonQuery()
            Button2.Text = "Добавить"
            'G_Rec_ID = -1
        End If
        NumericUpDown1.Value = 0
        NumericUpDown2.Value = 0
        TextBox1.Text = ""
        NUD_Focus()
        Stat()
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Close()
    End Sub
 
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        cn.Close()
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If IO.File.Exists(Application.StartupPath & "\Admin.txt") Then Admin = True
        cn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\1.mdb")
        cn.Open()
        Label4.Text = Now.ToLongDateString
        Stat()
        Show()
        NUD_Focus()
        Button6.Enabled = Admin
    End Sub
 
    Sub Stat()
        GetBalance()
        GetSummToday()
        GetSummYear()
        GetSumm30Days()
        DGV_Today()
    End Sub
 
    Private Sub NumericUpDown2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown2.ValueChanged
        If NumericUpDown2.Value > 0 Then
            NumericUpDown1.Value = 0
            NumericUpDown1.Enabled = False
        Else
            NumericUpDown1.Enabled = True
        End If
    End Sub
 
    Private Sub NumericUpDowns_KeyDown(ByVal s As NumericUpDown, ByVal e As System.Windows.Forms.KeyEventArgs) Handles NumericUpDown1.KeyDown, NumericUpDown2.KeyDown
        If e.KeyCode = Keys.Delete Then s.Value = 0
        If e.KeyCode = Keys.Enter Then
            e.SuppressKeyPress = True
            If s.Value = 0 Then Exit Sub
            TextBox1.Focus()
        End If
    End Sub
 
    Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
        If NumericUpDown1.Value > 0 Then
            NumericUpDown2.Value = 0
            NumericUpDown2.Enabled = False
        Else
            NumericUpDown2.Enabled = True
        End If
    End Sub
 
    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If TextBox1.TextLength = 0 Then Exit Sub
        If e.KeyCode = Keys.Enter Then
            e.SuppressKeyPress = True
            Button2.Focus()
        End If
    End Sub
 
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If DataGridView1.SelectedCells.Count = 0 Then Exit Sub
        Dim Rec_ID As Integer = DataGridView1.SelectedCells(0).Value
        Dim DeleteCommand As New OleDb.OleDbCommand("DELETE * from Calculate Where [Код] = " & Rec_ID, cn)
        DeleteCommand.ExecuteNonQuery()
        Stat()
    End Sub
 
    Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
        TextBox1.Text = DataGridView1.SelectedCells(1).Value
        If DataGridView1.SelectedCells(3).Value > 0 Then
            NumericUpDown1.Value = DataGridView1.SelectedCells(3).Value
        Else
            NumericUpDown2.Value = DataGridView1.SelectedCells(3).Value * -1
        End If
        G_Rec_ID = DataGridView1.SelectedCells(0).Value
        Button2.Text = "Сохранить"
    End Sub
 
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Form2.Show()
    End Sub
 
    'User Subs
    Sub NUD_Focus()
        NumericUpDown2.Focus()
        NumericUpDown2.Select(0, 4)
        NumericUpDown2.Value = 0
    End Sub
 
    Function AccDate(ByVal D As Date) As String
        Return "#" & D.ToString("MM/dd/yyyy").Replace(".", "/") & "#"
    End Function
 
    Sub GetBalance()
        Label7.Text = Labels("Select SUM(Цена) AS Price from Calculate")
    End Sub
 
    Sub GetSummToday()
        Label1.Text = -Labels("Select SUM(Цена) AS Price from Calculate Where [Дата] = " & AccDate(Now) & " AND [Цена] < 0")
    End Sub
 
    Sub GetSumm30Days()
        Label10.Text = -Labels("Select SUM(Цена) AS Price from Calculate Where [Дата] BETWEEN " & AccDate(Now.AddDays(-30)) & " AND " & AccDate(Now) & " AND [Цена] < 0")
    End Sub
 
    Sub GetSummYear()
        Dim BeginYear As Date = "01.01." & Now.Year
        Label8.Text = -Labels("Select SUM(Цена) AS Price from Calculate Where [Дата] > " & AccDate(BeginYear) & " AND [Цена] < 0")
    End Sub
 
    Function Labels(ByVal Comm As String) As String
        da.SelectCommand = New OleDb.OleDbCommand(comm, cn)
        Dim Sum As New DataTable
        da.Fill(Sum)
        If Sum.Rows.Count > 0 AndAlso Sum(0)(0).ToString <> "" Then
            Return Format(Sum(0)(0), "0,00") & " грн."
        End If
        Return "0,00 грн."
    End Function
 
    Private Sub DGV_Today()
        da.SelectCommand = New OleDb.OleDbCommand("Select * from Calculate Where [Дата] = " & AccDate(Now), cn)
        Dim Data As New DataTable
        da.Fill(Data)
        Fill_DGV(Data)
    End Sub
 
    Sub Fill_DGV(ByVal Tbl As DataTable)
        DataGridView1.DataSource = Tbl
        DataGridView1.Columns(0).Visible = 0
        DataGridView1.Columns(1).Width = 120
        DataGridView1.Columns(2).Width = 65
        DataGridView1.Columns(3).Width = 60
        DataGridView1.Columns(4).Width = 60
    End Sub
End Class
собственно ругается в этом месте
 Sub GetSummToday()
        Label1.Text = -Labels("Select SUM(Цена) AS Price from Calculate Where [Дата] = " & AccDate(Now) & " AND [Цена] < 0")
    End Sub

Решение задачи: «Приведение строки "0,00 р." к типу "Double" является недопустимым»

textual
Листинг программы
Fill_DGV(calcAdapter.GetData)

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

13   голосов , оценка 4.385 из 5
Похожие ответы