Olá pessoal,
Sou novo aquí e tambem com C#.
Estou utilizando em minha aplicação este pedaço de código onde preencho os dados de alguns
textbox. Até aí tudo ok:
private
void TelaClientes_Load(object sender, EventArgs e)
{
DataSet ds = CarregaSleClientes("SELECT TOP 1 CODIGO,CLIENTE ROM CLIENTE","CLIENTE");
cCODIGO.DataBindings.Add("Text", ds, "CLIENTE.CODIGO");
cNOME.DataBindings.Add("Text", ds, "CLIENTE.CLIENTE");
}
private DataSet CarregaSleClientes(string cQuery, string cDSNome)
{
string cnxS = ClasseConexaoMsSql.ConnectionString;
SqlConnection cnx = new SqlConnection(cnxS);
SqlDataAdapter da = new SqlDataAdapter(cQuery, cnx);
DataSet ds = new DataSet();
da.Fill(ds, cDSNome);
cnx.Close();
return ds;
}
Porém quando seleciono outro cliente via botão "buscar" no menu do form e tento prencher os textboxes com os novos dados:
private
void buscarToolStripMenuItem_Click(object sender, EventArgs e)
{
DataSet ds = CarregaSleClientes("SELECT CODIGO,CLIENTE FROM CLIENTE WHERE CODIGO = '00002' ", "CLIENTE");
cCODIGO.DataBindings.Add(
"Text", ds, "CLIENTE.CODIGO");
cNOME.DataBindings.Add(
"Text", ds, "CLIENTE.CLIENTE");
}
recebo esta exceção:
"This causes two bindings in the collection to bind to the same property.
Parameter name: binding"
por favor, o que faço pra dar certo?
Outra pergunta. Tenho este method Limpar() que peguei em um site.
Como é que instancio/aciono ele no meu form? Limpar(this controls); ?
private
void Limpar(Control controle)
{
foreach (Control c in controle.Controls)
{
if (c is TextBox)
c.Text =
"";
if (c is CheckBox)
(c
as CheckBox).Checked = false;
}
}