[英]Add Parameter to Data Grid View
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.我试图创建一个 SqlCommand 但没有机会使用 DataSet。
Can someone please help me with the corret way to insert @resultado_id_empresa as parameter?有人可以帮我插入@resultado_id_empresa 作为参数的正确方法吗?
Thanks!!谢谢!!
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 = ...;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.