0
Hi, I’m trying to bring in for a Label
a database registration data, for example:
when the person selects the product on ComboBox
the price of the product on label
However, I don’t think I’m getting the code question right, if someone can shed some light
code used:
private void cbxPeca_SelectedValueChanged(object sender, EventArgs e)
{
string strSelect = "SELECT Preco FROM Produto WHERE Preco LIKE (@Preco)";
using (MySqlConnection conn = new MySqlConnection("server=127.0.0.1;database=ProdPacote; Uid=root; pwd=1234;"))
{
MySqlDataAdapter da = new MySqlDataAdapter(strSelect, conn);
//Passagem por parâmetros.
da.SelectCommand.Parameters.AddWithValue("@preco", cbxPeca.Text + "%");
DataSet ds = new DataSet();
da.Fill(ds, "Preco");
label4.Text = ds.Tables["Preco"];
}
}
label4.Text = ds.Tables["Preco"]
you’re trying to put an objectTables
label? It would have to be the column value in a row, something likelabel4.Text = ds.Tables["Preco"].Rows[0]["nomedacoluna"]
– Ricardo Pontual
actually I wanted to pull this column(Price) from the product table to a variable, but I decided to try to pull to a
label
to test out first– Pietro Nunciaroni
in the way you showed the
ds.Tables["Preco"].Rows[0]["nomedacoluna"]
I put asds.Tables["Preco"].Rows[0]["Preco"]
but gets it wrong (that red line at the bottom)– Pietro Nunciaroni
need to see what error is, pass the mouse and take a look. I would guess that it is a type conversion, maybe for a
.ToString()
at the end solve, but first we need to know if returned something, then check if theRows
has some return– Ricardo Pontual
It worked, The mistakes are gone, but still does not appear in
label
the price of the product when selecting the name of the product in theComboBox
– Pietro Nunciaroni
I tried to pass using this code
label4 = passando.ToString();
but he speaks that he cannot convert implicitly typestring
insystem.windows.forms.label
– Pietro Nunciaroni