estimado Posted February 21, 2012 at 11:47 AM Report Share #440537 Posted February 21, 2012 at 11:47 AM boas Podem-me ajudar? Aparecem-me estes erros, mas não sei como os tirar! http://img821.imageshack.us/img821/6662/semttuloigg.png Obrigado Visual Studio 2010 C# Link to comment Share on other sites More sharing options...
Andrepereira9 Posted February 21, 2012 at 12:33 PM Report Share #440542 Posted February 21, 2012 at 12:33 PM Boas Dá-te erro, porque estás a utilizar TextBoxs Utiliza antes MaskedTextBoxs A informática chegou para resolver problemas que antes não existiam Quem ri por último é porque está conectado a 52 Kbs. Link to comment Share on other sites More sharing options...
estimado Posted February 21, 2012 at 12:52 PM Author Report Share #440544 Posted February 21, 2012 at 12:52 PM boas Não, eu estou a utilizar MaskedTextBoxs Aliás, onde eu coloquei o codigo é um "ComboBox" Só se eu tiver alguns erros no codigo, poderão me ver sff? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace Sistema_Manutenção { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'bdclienteDataSet1.Table_1' table. You can move, or remove it, as needed. this.table_1TableAdapter.Fill(this.bdclienteDataSet1.Table_1); this.reportViewer1.RefreshReport(); } private void label4_Click(object sender, EventArgs e) { } private void label2_Click(object sender, EventArgs e) { } private void cbmFiltrar_SelectedIndexChanged(object sender, EventArgs e) { } private void cbmFiltrar_SelectedIndexChanged_1(object sender, EventArgs e) { } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (cbmFiltrar.Text == "Código") { txtPesquisar.Mask = ""; } if (cbmFiltrar.Text == "Nome") { txtPesquisar.Mask = ""; } if (cbmFiltrar.Text == "CPF") { txtPesquisar.Mask = "000,000,000-00"; } if (cbmFiltrar.Text == "") { txtPesquisar.Mask = ""; } } private void btnPesquisar_Click(object sender, EventArgs e) { try { if ((txtPesquisaFuncionario.Text != "") && (txtPesquisaMesAno.Text != "")) { string sql = "SELECT * FROM tbBercario WHERE Funcionario LIKE '%" + txtPesquisaFuncionario.Text + "%' AND MesAno=" + txtPesquisaMesAno.Text + ""; cmd = new SqlCommand(sql, cn); cn.Open(); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable tbBbercario = new DataTable(); da.Fill(tbBbercario); tdBercarioDataGridView.DataSource = tbBbercario; } else if ((txtPesquisaFuncionario.Text != "") && (txtPesquisaMesAno.Text == "")) { string sql = "SELECT * FROM tbBercario WHERE Funcionario LIKE '%" + txtPesquisaFuncionario.Text + "%'"; cmd = new SqlCommand(sql, cn); cn.Open(); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable tbBbercario = new DataTable(); da.Fill(tbBbercario); tdBercarioDataGridView.DataSource = tbBbercario; } else { MessageBox.Show("Preencha os campos!"); } } catch (Exception ex) { //Caso haja uma exceção MessageBox.Show(ex.Message); } finally { //Fechar a conexão cn.Close(); } } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { { //Limpar a GroupBox LimparCampo(); //O Campo codFuncionario recebe da datagrid tbCliente a celula número 0 e assim por diante codFuncionarioTextBox.Text = tbClienteDataGridView.CurrentRow.Cells[0].Value.ToString(); nomeTextBox.Text = tbClienteDataGridView.CurrentRow.Cells[1].Value.ToString(); cpfMaskedTextBox.Text = tbClienteDataGridView.CurrentRow.Cells[2].Value.ToString(); telephoneMaskedTextBox.Text = tbClienteDataGridView.CurrentRow.Cells[3].Value.ToString(); } } } } Visual Studio 2010 C# Link to comment Share on other sites More sharing options...
Gonka Posted February 21, 2012 at 01:55 PM Report Share #440547 Posted February 21, 2012 at 01:55 PM O erro indica que estás a usar TextBox... Link to comment Share on other sites More sharing options...
estimado Posted February 21, 2012 at 02:03 PM Author Report Share #440548 Posted February 21, 2012 at 02:03 PM boas Não, só estou a utilizar uma TextBox, que é antes do Button "Pesquisar" mais nada! http://img256.imageshack.us/img256/3781/semttulown.png Visual Studio 2010 C# Link to comment Share on other sites More sharing options...
estimado Posted February 21, 2012 at 03:43 PM Author Report Share #440570 Posted February 21, 2012 at 03:43 PM Eu tenho o ComboBox! Não sei porque que nao me da! Podem-me ajudar? O código que implementei está mesmo na ComboBox! if (cbmFiltrar.Text == "Código") { txtPesquisar.Mask = ""; } if (cbmFiltrar.Text == "Nome") { txtPesquisar.Mask = ""; } if (cbmFiltrar.Text == "CPF") { txtPesquisar.Mask = "000,000,000-00"; } if (cbmFiltrar.Text == "") { txtPesquisar.Mask = ""; } Agradecia uma ajuda vossa sff obrigado desde já Visual Studio 2010 C# Link to comment Share on other sites More sharing options...
Caça Posted February 21, 2012 at 09:28 PM Report Share #440617 Posted February 21, 2012 at 09:28 PM Só as MaskedTextBoxs é que tem a propriedade Mask. Se estás a tentar utiliza-la em outro objecto que não a tenha, é normal que dê erro. Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
estimado Posted February 21, 2012 at 10:15 PM Author Report Share #440623 Posted February 21, 2012 at 10:15 PM boas Como meti na imagem: http://img535.imageshack.us/img535/4647/semttulovdf.png Esta tudo correcto! Será que tenho algum erro no codigo? O codigo que estou a utilizar é este: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace Sistema_Manutenção { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'bdclienteDataSet.tbcliente' table. You can move, or remove it, as needed. this.tbclienteTableAdapter.Fill(this.bdclienteDataSet.tbcliente); } private void cbmFiltrar_SelectedIndexChanged(object sender, EventArgs e) { if (cbmFiltrar.Text == "Código") { txtPesquisar.Mask = ""; } if (cbmFiltrar.Text == "Nome") { txtPesquisar.Mask = ""; } if (cbmFiltrar.Text == "CPF") { txtPesquisar.Mask = "000,000,000-00"; } if (cbmFiltrar.Text == "") { txtPesquisar.Mask = ""; } } private void btnPesquisar_Click(object sender, EventArgs e) { try { if ((txtPesquisaFuncionario.Text != "") && (txtPesquisaMesAno.Text != "")) { string sql = "SELECT * FROM tbBercario WHERE Funcionario LIKE '%" + txtPesquisaFuncionario.Text + "%' AND MesAno=" + txtPesquisaMesAno.Text + ""; cmd = new SqlCommand(sql, cn); cn.Open(); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable tbBbercario = new DataTable(); da.Fill(tbBbercario); tdBercarioDataGridView.DataSource = tbBbercario; } else if ((txtPesquisaFuncionario.Text != "") && (txtPesquisaMesAno.Text == "")) { string sql = "SELECT * FROM tbBercario WHERE Funcionario LIKE '%" + txtPesquisaFuncionario.Text + "%'"; cmd = new SqlCommand(sql, cn); cn.Open(); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable tbBbercario = new DataTable(); da.Fill(tbBbercario); tdBercarioDataGridView.DataSource = tbBbercario; } else { MessageBox.Show("Preencha os campos!"); } } catch (Exception ex) { //Caso haja uma exceção MessageBox.Show(ex.Message); } finally { //Fechar a conexão cn.Close(); } } private void LimparCampo() { foreach (Control c in Controls) { if (c is GroupBox) { for (int i = 0; i < c.Controls.Count; i++) { if (c.Controls[i] is TextBox) { (c.Controls[i] as TextBox).Text = ""; } if (c.Controls[i] is MaskedTextBox) { (c.Controls[i] as MaskedTextBox).Text = ""; } if (c.Controls[i] is ComboBox) { (c.Controls[i] as ComboBox).Text = ""; } } } } } private void tbClienteDataGridView_Click(object sender, EventArgs e) { //Limpar a GroupBox LimparCampo(); //O Campo codFuncionario recebe da datagrid tbCliente a celula número 0 e assim por diante codFuncionarioTextBox.Text = tbClienteDataGridView.CurrentRow.Cells[0].Value.ToString(); nomeTextBox.Text = tbClienteDataGridView.CurrentRow.Cells[1].Value.ToString(); cpfMaskedTextBox.Text = tbClienteDataGridView.CurrentRow.Cells[2].Value.ToString(); telephoneMaskedTextBox.Text = tbClienteDataGridView.CurrentRow.Cells[3].Value.ToString(); } } } Poderiam-me ver qual e o problema? Visual Studio 2010 C# Link to comment Share on other sites More sharing options...
anolsi Posted February 21, 2012 at 10:20 PM Report Share #440626 Posted February 21, 2012 at 10:20 PM O teu problema é que estás a aplicar a Mask à textBox e não às maskedtextBoxes que tens, como já te foi dito. Vê se começas a ler o que te dizem. O txtPesquisar é uma TexteBox, e não deveria ser. "Nós somos o que fazemos repetidamente, a excelência não é um feito, e sim, um hábito."Não respondo a questões por PM que possam ser colocadas no fórum! Link to comment Share on other sites More sharing options...
estimado Posted February 21, 2012 at 11:01 PM Author Report Share #440630 Posted February 21, 2012 at 11:01 PM boas Obrigado 😛 Só mais uma coisa! Agora esta-me a aparecer outros erros! using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace Sistema_Manutenção { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'bdclienteDataSet.tbcliente' table. You can move, or remove it, as needed. this.tbclienteTableAdapter.Fill(this.bdclienteDataSet.tbcliente); } private void cbmFiltrar_SelectedIndexChanged(object sender, EventArgs e) { } private void btnPesquisar_Click(object sender, EventArgs e) { try { if (cbmFiltrar.Text == "Código") { //Define a instrução Sql string sql = "SELECT * FROM tbCliente WHERE codFuncionario =" + txtPesquisar.Text + ""; //Lê os dados da variavel sql e conectar no cn cmd = new SqlCommand(sql, cn); //Abre conexão cn.Open(); //Define o valor da CommandType para cmd cmd.CommandType = CommandType.Text; /*Representa um conjunto de comandos de dados e uma conexão de banco de dados * que são usados para preencher o DataSet e atualizar um banco de dados SQL Server.*/ SqlDataAdapter da = new SqlDataAdapter(cmd); //Representa uma tabela de dados na memória. DataTable cliente = new DataTable(); /* Adiciona ou atualiza linhas em um DataTable para que correspondam na fonte de * dados usando o DataTable.*/ da.Fill(cliente); /*A tbClienteDataGridView recebe o DataTable cliente*/ tbClienteDataGridView.DataSource = cliente; //Fechar a conexão } if (cbmFiltrar.Text == "Nome") { //define a instrução SQL string sql = "SELECT * FROM tbCliente WHERE cliente LIKE '%" + txtPesquisar.Text + "%'"; cmd = new SqlCommand(sql, cn); cn.Open(); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable cliente = new DataTable(); da.Fill(cliente); tbClienteDataGridView.DataSource = cliente; } if (cbmFiltrar.Text == "CPF") { //define a instrução SQL string sql = "SELECT * FROM tbCliente WHERE CPF ='" + txtPesquisar.Text + "'"; cmd = new SqlCommand(sql, cn); cn.Open(); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable cliente = new DataTable(); da.Fill(cliente); tbClienteDataGridView.DataSource = cliente; } if (cbmFiltrar.Text == "") { //define a instrução SQL string sql = "SELECT * FROM tbCliente"; cmd = new SqlCommand(sql, cn); cn.Open(); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable cliente = new DataTable(); da.Fill(cliente); tbClienteDataGridView.DataSource = cliente; } } catch (Exception ex) { //Caso haja uma exceção MessageBox.Show(ex.Message); } finally { //Fechar a conexão cn.Close(); } } private void tbClienteDataGridView_Click(object sender, EventArgs e) { } private void LimparCampo() { foreach (Control c in Controls) { if (c is GroupBox) { for (int i = 0; i < c.Controls.Count; i++) { if (c.Controls[i] is TextBox) { (c.Controls[i] as TextBox).Text = ""; } if (c.Controls[i] is MaskedTextBox) { (c.Controls[i] as MaskedTextBox).Text = ""; } if (c.Controls[i] is ComboBox) { (c.Controls[i] as ComboBox).Text = ""; } } } } } private void tbClienteDataGridView_Click(object sender, EventArgs e) { //Limpar a GroupBox LimparCampo(); //O Campo codFuncionario recebe da datagrid tbCliente a celula número 0 e assim por diante codFuncionarioTextBox.Text = tbClienteDataGridView.CurrentRow.Cells[0].Value.ToString(); nomeTextBox.Text = tbClienteDataGridView.CurrentRow.Cells[1].Value.ToString(); cpfMaskedTextBox.Text = tbClienteDataGridView.CurrentRow.Cells[2].Value.ToString(); telephoneMaskedTextBox.Text = tbClienteDataGridView.CurrentRow.Cells[3].Value.ToString(); } private void txtPesquisar_TextChanged(object sender, EventArgs e) { } private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) { if (cbmFiltrar.Text == "Código") { txtPesquisar.Mask = ""; } if (cbmFiltrar.Text == "Nome") { txtPesquisar.Mask = ""; } if (cbmFiltrar.Text == "CPF") { txtPesquisar.Mask = "000,000,000-00"; } if (cbmFiltrar.Text == "") { txtPesquisar.Mask = ""; } } } } A dizer: O cn não existe no contexto O cmd não existe no contexto Podem-me ajudar novamente? obrigado Visual Studio 2010 C# Link to comment Share on other sites More sharing options...
Caça Posted February 21, 2012 at 11:08 PM Report Share #440633 Posted February 21, 2012 at 11:08 PM Não tens essas varáveis declaradas. Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
estimado Posted February 21, 2012 at 11:10 PM Author Report Share #440634 Posted February 21, 2012 at 11:10 PM Não as tenho declaradas como assim? Podes-me ajudar? obrigado Visual Studio 2010 C# Link to comment Share on other sites More sharing options...
Gonka Posted February 23, 2012 at 09:33 AM Report Share #440805 Posted February 23, 2012 at 09:33 AM SqlCommand cmd = new SqlCommand(...); Link to comment Share on other sites More sharing options...
estimado Posted February 23, 2012 at 01:06 PM Author Report Share #440828 Posted February 23, 2012 at 01:06 PM obrigado 😁 Visual Studio 2010 C# Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now