Problem when saving a Visual Basic combo box data in SQL Server database

0

Good morning, I'm doing an insert from Visual Basic in a SQL Server database from a ComboBox that I'm filling from a database, at the time of saving the data, in the database me gurda the following:

I have it in classes

Insert complaints

Function Insertar_Queja(ByVal CLIENTE As String, ByVal DIRECCION As String, ByVal CONTACTO As String,
                  ByVal VENDEDOR As String, ByVal FECHA As Date, ByVal OBSERVACIONES As String, ByVal NOTCREDITO As String) As String

    Dim salida As String = "Se genero el Reclamo"
    Try
        cmd = New SqlCommand("Sp_InsertarQUeja", cn)
        cmd.CommandType = CommandType.StoredProcedure
        With cmd.Parameters
            .AddWithValue("@Cliente", CLIENTE)
            .AddWithValue("@DIreccion", DIRECCION)
            .AddWithValue("@Contacto", CONTACTO)
            .AddWithValue("@Vendedor", VENDEDOR)
            .AddWithValue("@Fecha", FECHA)
            .AddWithValue("@Observaciones", OBSERVACIONES)
            .AddWithValue("@Nota_Credito", NOTCREDITO)
        End With
        cmd.ExecuteNonQuery()
    Catch ex As Exception
        salida = "No se genero debido a: " + ex.ToString
    End Try
    Return salida
End Function

and on the button I have the following:

    MsgBox(conn.Insertar_Queja(CmbCliente.SelectedItem.ToString, TxtDireccion.Text, TxtContacto.Text, CmbVendedor.SelectedItem.ToString, CDate(Dtp1.Text), TxtObservaciones.Text, CmbNotaCredito.SelectedItem.ToString))

All calls from this store procedure:

@Cliente as varchar (50),
@Direccion as varchar (50),
@Contacto as varchar (50),
@Vendedor as varchar(50),
@Fecha as date,
@Observaciones as varchar(500),
@Nota_Credito as varchar(50)

as

insert RECLAMOS
(Cliente,Direccion,Contacto,Vendedor,Fecha,Observaciones,Nota_Credito)
values
(@Cliente,@Direccion,@Contacto,@Vendedor,@Fecha,@Observaciones,@Nota_Credito)
    
asked by Cristopher Salay 25.10.2017 в 16:21
source

1 answer

0

CmbCliente.SelectedItem is your case a DataRowView , even if you only have one column. The ToString of a DataRowView simply returns a string with the name of the class.

In your case, there are at least two options to obtain that data:

1.- Use SelectedValue instead of SelectedItem . If when loading the data in your ComboBox you have correctly set the property ValueMember , there you will have the value of the selected field:

MsgBox(conn.Insertar_Queja(CmbCliente.SelectedValue.ToString, TxtDireccion.Text, TxtContacto.Text, CmbVendedor.SelectedItem.ToString, CDate(Dtp1.Text), TxtObservaciones.Text, CmbNotaCredito.SelectedItem.ToString))

2.- Make a cast of SelectedItem to its authentic type ( DataRowView in your case) and get the value of the column that interests you within the selected item:

MsgBox(conn.Insertar_Queja(((DataRowView)CmbCliente.SelectedItem)[0].ToString(), TxtDireccion.Text, TxtContacto.Text, CmbVendedor.SelectedItem.ToString, CDate(Dtp1.Text), TxtObservaciones.Text, CmbNotaCredito.SelectedItem.ToString))

or by column name:

MsgBox(conn.Insertar_Queja(((DataRowView)CmbCliente.SelectedItem)["nombreColumna"].ToString(), TxtDireccion.Text, TxtContacto.Text, CmbVendedor.SelectedItem.ToString, CDate(Dtp1.Text), TxtObservaciones.Text, CmbNotaCredito.SelectedItem.ToString))
    
answered by 25.10.2017 / 17:02
source