Buongiorno, io volevo fare una somma e poi mandarla in una datagridview ma esce:
Cast non valido dalla stringa "" al tipo 'Double'.'
Imports System.Data.OleDb
Imports System.IO
Public Class Form1
Public Function SommaPrezzi() As Double
Dim i As Integer
Dim totale As Double
Dim totale2 As Double
Dim null1 As String = ""
For i = 0 To ListBox1.Items.Count - 1 'Se usi il Vb.net metti listaprezzi.items.count
totale = totale + ListBox1.Items(i)
Next
SommaPrezzi = totale
ListBox1.Items.Add(null1)
ListBox1.Items.Add("Ore complessive")
ListBox1.Items.Add(SommaPrezzi)
End Function
Public Function SommaPrezzi2() As Double
Dim i As Integer
Dim totale2 As Double
Dim prodotto2 As Integer
Dim null1 As String = ""
For i = 0 To ListBox2.Items.Count - 1 'Se usi il Vb.net metti listaprezzi.items.count
totale2 = totale2 + ListBox2.Items(i)
Next
SommaPrezzi2 = totale2
ListBox2.Items.Add(null1)
ListBox2.Items.Add("Ore complessive")
ListBox2.Items.Add(SommaPrezzi2)
End Function
Public Function DataGridView() As Integer
Dim somma As Integer
Dim i As Integer
For i = 0 To ListBox2.Items.Count - 1 'Se usi il Vb.net metti listaprezzi.items.count
'Si frema qua----->' somma = somma + ListBox2.Items(i)
Next
DataGridView = somma
End Function
Dim Conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\ingfr\Documents\Database1.accdb")
Dim Conn2 As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\ingfr\Documents\Database1.accdb")
Dim Conn3 As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\ingfr\Documents\Database1.accdb")
Dim reader2 As OleDbDataReader
Dim reader3 As OleDbDataReader
Dim da As OleDbDataAdapter
Dim cmb As OleDbCommandBuilder
Dim reader As OleDbDataReader
Dim ds As DataSet = New DataSet()
Dim tables As DataTableCollection
Dim dt As New DataTable
Dim source1 As New BindingSource
Dim bs As New BindingSource() ' BindingSource
Dim SQLString As OleDbCommand
Dim SQLString2 As OleDbCommand
Dim SQLString3 As OleDbCommand
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
SQLString = New OleDbCommand("SELECT * FROM bianca WHERE commessa='" + TextBox1.Text + "'", Conn)
Conn.Open()
reader = SQLString.ExecuteReader()
While (reader.Read())
ListBox1.Items.Add(reader.GetString(1))
End While
reader.Close()
Conn.Close()
ListBox2.Items.Clear()
SQLString2 = New OleDbCommand("SELECT * FROM gaetano WHERE commessa='" + TextBox1.Text + "'", Conn2)
Conn2.Open()
reader2 = SQLString2.ExecuteReader()
While (reader2.Read())
ListBox2.Items.Add(reader2.GetString(1))
End While
reader2.Close()
Conn2.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs)
Call SommaPrezzi()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Gaetano.Click
Dim cnn As New OleDbConnection("Provider= Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ingfr\Documents\Database1.accdb")
With cnn
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ingfr\Documents\Database1.accdb"
.Open()
End With
Dim dt As New DataTable
Dim da As New OleDb.OleDbDataAdapter("SELECT Costo_orario from Costi WHERE Nome='Gaetano'", cnn)
da.Fill(dt)
If dt.Rows.Count > 0 Then
With ComboBox2
.Items.Clear()
For i As Integer = 0 To dt.Rows.Count - 1
.Items.Add(dt.Rows(i).Item("Costo_orario"))
Next
.SelectedIndex = -1
End With
End If
With cnn
.Close()
.Dispose()
End With
End Sub
Private Sub Button4_Click_1(sender As Object, e As EventArgs) Handles Bianca.Click
Dim cnn As New OleDbConnection("Provider= Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ingfr\Documents\Database1.accdb")
With cnn
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ingfr\Documents\Database1.accdb"
.Open()
End With
Dim dt As New DataTable
Dim da As New OleDb.OleDbDataAdapter("SELECT Costo_orario from Costi WHERE Nome='Bianca'", cnn)
da.Fill(dt)
If dt.Rows.Count > 0 Then
With ComboBox1
.Items.Clear()
For i As Integer = 0 To dt.Rows.Count - 1
.Items.Add(dt.Rows(i).Item("Costo_orario"))
Next
.SelectedIndex = -1
End With
End If
With cnn
.Close()
.Dispose()
End With
End Sub
Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
Dim prodotto As Integer
Dim null1 As String = ""
prodotto = SommaPrezzi() * ComboBox1.Text
ListBox1.Items.Add(null1)
ListBox1.Items.Add("Costo Complessivo")
ListBox1.Items.Add(prodotto)
Dim prodotto2 As Integer
prodotto2 = SommaPrezzi2() * ComboBox2.Text
ListBox2.Items.Add(null1)
ListBox2.Items.Add("Costo Complessivo")
ListBox2.Items.Add(prodotto2)
Dim totale As Integer
totale = prodotto + prodotto2
ListBox3.Items.Add("Costo Totale Commessa")
ListBox3.Items.Add(null1)
ListBox3.Items.Add(totale)
DataGridView1.Rows.Insert(0, "Gaetano", DataGridView)
End Sub
End Class