Acessando dados com Textboxes e botões de navegação
Ola pessoal como faço para fazer botoes de navegação (primeiro, seguinte, ultimo)
Achei um topico semelhante porem gostaria de fazer com o banco sql server e no modelo esta em acess.
http://www.edibertoalves.com.br/blog/acessando-dados-com-textboxes-e-botoes-de-navegacao/comment-page-1/#comment-1004
Achei um topico semelhante porem gostaria de fazer com o banco sql server e no modelo esta em acess.
http://www.edibertoalves.com.br/blog/acessando-dados-com-textboxes-e-botoes-de-navegacao/comment-page-1/#comment-1004
Sigrids Lima
Curtidas 0
Respostas
Joel Rodrigues
19/06/2012
Cara, o raciocínio é exatamente o mesmo, você só precisa mudar as classes de OleDb para Sql (SqlConnection, SqlCommand, etc) e alterar a string de conexão.
GOSTEI 0
Sigrids Lima
19/06/2012
Os erros deram o seguinte:
no button primeiro
if (recuperaTabelaClientes().Rows.Count > 0)
no button proximo
if (Contador < recuperaTabelaClientes().Rows.Count - 1)
ERROR 1 )expected
ERROR 2 Invalid expression term )
ERROR 3 )expected
ERROR 4 )expected
ERROR 5 )expected
ERROR 6 Invalid expression term )
ERROR 7 ; expected
ERROR 8 ; expected
ERROR 9 The name gt does not exist in the current context
ERROR 10 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
ERROR 11 The name lt does not exist in the current context
ERROR 12 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
ERROR 13 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
CODE
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 navegaçã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 proximoDataSet.tabela table. You can move, or remove it, as needed.
this.tabelaTableAdapter.Fill(this.proximoDataSet.tabela);
}
private DataTable recuperaTabelaClientes()
{
string Conexao = @Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\proximo.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;;
string vSQL = select codigo, nome, sobrenome from tabela;
SqlConnection vConn = new SqlConnection(Conexao);
SqlDataAdapter vDataAdapter = new SqlDataAdapter(vSQL, vConn);
DataTable vTable = new DataTable();
vDataAdapter.Fill(vTable);
return vTable;
}
int Contador;
private void btnPrimeiro_Click(object sender, EventArgs e)
{
if (recuperaTabelaClientes().Rows.Count > 0)
{
Contador = 0;
txtCodigo.Text = recuperaTabelaClientes().Rows[Contador][codigo].ToString();
txtNome.Text = recuperaTabelaClientes().Rows[Contador][nome].ToString();
txtSobrenome.Text = recuperaTabelaClientes().Rows[Contador][sobrenome].ToString();
dataGridView1.CurrentCell = dataGridView1.Rows[Contador].Cells[codigo];
}
}
private void btnAnterior_Click(object sender, EventArgs e)
{
if (Contador == recuperaTabelaClientes().Rows.Count - 1 || Contador != 0)
{
Contador--;
txtCodigo.Text = recuperaTabelaClientes().Rows[Contador][codigo].ToString();
txtNome.Text = recuperaTabelaClientes().Rows[Contador][nome].ToString();
txtSobrenome.Text = recuperaTabelaClientes().Rows[Contador][sobrenome].ToString();
dataGridView1.CurrentCell = dataGridView1.Rows[Contador].Cells[codigo];
}
}
private void btnProximo_Click(object sender, EventArgs e)
{
if (Contador < recuperaTabelaClientes().Rows.Count - 1)
{
Contador++;
DataGridViewRow vGridRow = dataGridView1.Rows[Contador];
txtCodigo.Text = recuperaTabelaClientes().Rows[Contador][codigo].ToString();
txtNome.Text = recuperaTabelaClientes().Rows[Contador][nome].ToString();
txtSobrenome.Text = recuperaTabelaClientes().Rows[Contador][sobrenome].ToString();
dataGridView1.CurrentCell = dataGridView1.Rows[Contador].Cells[codigo];
}
}
private void btnUltimo_Click(object sender, EventArgs e)
{
Contador = recuperaTabelaClientes().Rows.Count - 1;
txtCodigo.Text = recuperaTabelaClientes().Rows[Contador][codigo].ToString();
txtNome.Text = recuperaTabelaClientes().Rows[Contador][nome].ToString();
txtSobrenome.Text = recuperaTabelaClientes().Rows[Contador][sobrenome].ToString();
dataGridView1.CurrentCell = dataGridView1.Rows[Contador].Cells[codigo];
}
}
}
no button primeiro
if (recuperaTabelaClientes().Rows.Count > 0)
no button proximo
if (Contador < recuperaTabelaClientes().Rows.Count - 1)
ERROR 1 )expected
ERROR 2 Invalid expression term )
ERROR 3 )expected
ERROR 4 )expected
ERROR 5 )expected
ERROR 6 Invalid expression term )
ERROR 7 ; expected
ERROR 8 ; expected
ERROR 9 The name gt does not exist in the current context
ERROR 10 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
ERROR 11 The name lt does not exist in the current context
ERROR 12 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
ERROR 13 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
CODE
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 navegaçã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 proximoDataSet.tabela table. You can move, or remove it, as needed.
this.tabelaTableAdapter.Fill(this.proximoDataSet.tabela);
}
private DataTable recuperaTabelaClientes()
{
string Conexao = @Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\proximo.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;;
string vSQL = select codigo, nome, sobrenome from tabela;
SqlConnection vConn = new SqlConnection(Conexao);
SqlDataAdapter vDataAdapter = new SqlDataAdapter(vSQL, vConn);
DataTable vTable = new DataTable();
vDataAdapter.Fill(vTable);
return vTable;
}
int Contador;
private void btnPrimeiro_Click(object sender, EventArgs e)
{
if (recuperaTabelaClientes().Rows.Count > 0)
{
Contador = 0;
txtCodigo.Text = recuperaTabelaClientes().Rows[Contador][codigo].ToString();
txtNome.Text = recuperaTabelaClientes().Rows[Contador][nome].ToString();
txtSobrenome.Text = recuperaTabelaClientes().Rows[Contador][sobrenome].ToString();
dataGridView1.CurrentCell = dataGridView1.Rows[Contador].Cells[codigo];
}
}
private void btnAnterior_Click(object sender, EventArgs e)
{
if (Contador == recuperaTabelaClientes().Rows.Count - 1 || Contador != 0)
{
Contador--;
txtCodigo.Text = recuperaTabelaClientes().Rows[Contador][codigo].ToString();
txtNome.Text = recuperaTabelaClientes().Rows[Contador][nome].ToString();
txtSobrenome.Text = recuperaTabelaClientes().Rows[Contador][sobrenome].ToString();
dataGridView1.CurrentCell = dataGridView1.Rows[Contador].Cells[codigo];
}
}
private void btnProximo_Click(object sender, EventArgs e)
{
if (Contador < recuperaTabelaClientes().Rows.Count - 1)
{
Contador++;
DataGridViewRow vGridRow = dataGridView1.Rows[Contador];
txtCodigo.Text = recuperaTabelaClientes().Rows[Contador][codigo].ToString();
txtNome.Text = recuperaTabelaClientes().Rows[Contador][nome].ToString();
txtSobrenome.Text = recuperaTabelaClientes().Rows[Contador][sobrenome].ToString();
dataGridView1.CurrentCell = dataGridView1.Rows[Contador].Cells[codigo];
}
}
private void btnUltimo_Click(object sender, EventArgs e)
{
Contador = recuperaTabelaClientes().Rows.Count - 1;
txtCodigo.Text = recuperaTabelaClientes().Rows[Contador][codigo].ToString();
txtNome.Text = recuperaTabelaClientes().Rows[Contador][nome].ToString();
txtSobrenome.Text = recuperaTabelaClientes().Rows[Contador][sobrenome].ToString();
dataGridView1.CurrentCell = dataGridView1.Rows[Contador].Cells[codigo];
}
}
}
GOSTEI 0
Joel Rodrigues
19/06/2012
Amigo, uma pergunta básica: você já programa mesmo em C#?
Veja em que linhas estão ocorrendo estes erros, pois aqui fica chato de analisar e se tratam de erros SIMPLES, como adicionar ou retirar um caractere.
Veja em que linhas estão ocorrendo estes erros, pois aqui fica chato de analisar e se tratam de erros SIMPLES, como adicionar ou retirar um caractere.
GOSTEI 0
Sigrids Lima
19/06/2012
Sou iniciante em c#, mais valeu pela dica irmaozinho o erro tava aqui < que é < deu algum erro na pagina onde peguei o topico.
valeu um abraço
valeu um abraço
GOSTEI 0
Joel Rodrigues
19/06/2012
Deu certo aí então? Se sim, que bom.
Ah, considere o uso de BindingSource para fazer essa navegação. Inclusive existe um componente que faz isso sozinho.
Boa sorte.
Ah, considere o uso de BindingSource para fazer essa navegação. Inclusive existe um componente que faz isso sozinho.
Boa sorte.
GOSTEI 0