-1

I need to add a parameter for search button populate my data grid view, but I don`t know how to.

try
        {
            conexaoBD();
            strSQL = "SELECT " +
                "a.nm_id 'ID', " +
                "b.ch_nome 'Empresa', " +
                "c.ch_nome 'Banco', " +
                "a.ch_resultado 'Resultado' " +
                "FROM tb_homologação_bancária_santander a INNER JOIN tb_parâmetros_empresas b ON a.nm_id_empresa = b.nm_id " +
                "INNER JOIN tb_parâmetros_bancos c ON a.nm_id_banco = c.nm_id " +
                "WHERE a.nm_id_empresa = @resultado_id_empresa";

            DataSet ds = new DataSet();
            da = new SqlDataAdapter(strSQL, conexao);

            conexao.Open();
            da.Fill(ds);
            dgvResultado.DataSource = ds.Tables[0];
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        finally
        {
            conexao.Close();
            conexao = null;
            comando = null;
        }

I tried to create a SqlCommand but no chance to work with DataSet.

Can someone please help me with the corret way to insert @resultado_id_empresa as parameter?

Thanks!!

  • 2
    Does this answer your question? [c# Using Parameters.AddWithValue in SqlDataAdapter](https://stackoverflow.com/questions/13276602/c-sharp-using-parameters-addwithvalue-in-sqldataadapter) – Fruchtzwerg Jul 05 '20 at 15:50

1 Answers1

0

Is that work ?

strSQL = "... WHERE a.nm_id_empresa = ?";

da = new SqlDataAdapter(strSQL, conexao);
da.SelectCommand.Parameters.Add("@ID", SqlDbType.Int /* or any relevant type*/).Value = ...;