per ora faccio così
codice:
Sub Aggiungi_Parametro(ByRef Sql As String, ByVal Etichetta As String, ByVal Valore As Object, ByRef cmd As SqlCommand)
If Not Valore Is Nothing Then
Sql = Sql.Replace("--" & Etichetta, "")
Dim Tipo As SqlDbType
If TypeOf Valore Is String Then
Tipo = SqlDbType.VarChar
ElseIf TypeOf Valore Is Date Then
Tipo = SqlDbType.DateTime
ElseIf TypeOf Valore Is Boolean Then
Tipo = SqlDbType.Bit
ElseIf TypeOf Valore Is Double Then
Tipo = SqlDbType.Float
ElseIf TypeOf Valore Is Integer Then
Tipo = SqlDbType.Int
ElseIf TypeOf Valore Is Long Then
Tipo = SqlDbType.BigInt
End If
cmd.Parameters.Add("@" & Etichetta, Tipo).Value = Valore
End If
End Sub
cioé data una variabile (Valore) non meglio specificata (la passo come object alla funzione perché può essere di diverso tipo) mi aggiunge un parametro al command del tipo opportuno, coerente col tipo vb della variabile.
Mi chiedevo se invece dei vari if (a proposito, sbaglio qualcosa oppure il select case non si può usare con typeof?) ci fosse una funzione del sistema che restituisce il tipo sql corrispondente al tipo vb della variabile.