diogom Posted April 11, 2012 at 08:19 PM Report #448668 Posted April 11, 2012 at 08:19 PM olá, quero preencher uma gridview com dados de uma base de dados. O problema é que não está a preencher e eu não estou a perceber pq. protected void Page_Load(object sender, EventArgs e) { userTB.Text = Session["nome"].ToString(); //Session.Remove("nome"); if (!IsPostBack) -----------------------------------------------------------------------> não entra neste if { if (userTB.Text.Contains("*?@?*.?*")) { carregardados(); } else { carregardados2(); } } } public void carregardados() { GridView1.Visible = false; //Label1.Text = ""; string query = ("Select mes,tiposervico,horasserv,preçohora,totalserv from mensalidades Where email '" + userTB.Text + "'order by mes"); String SERVIDOR = "localhost"; String BANCO = ""; String USUARIO = ""; String SENHA = ""; String stringConexao = "Database=" + BANCO + ";Data Source=" + SERVIDOR + ";User Id=" + USUARIO + ";Password=" + SENHA + "; pooling=false"; MySqlConnection conexao = new MySqlConnection(stringConexao); MySqlDataAdapter myAdapter = new MySqlDataAdapter(); DataSet dataset = new DataSet(); try { myAdapter.SelectCommand = new MySqlCommand(query, conexao); myAdapter.Fill(dataset); GridView1.DataSource = dataset; GridView1.DataBind(); GridView1.Visible = true; } catch (MySqlException erro) { MessageBox.Show("erro " + erro); } catch (Exception ex) { MessageBox.Show("erro inesperado " + ex); } finally { dataset.Dispose(); myAdapter.Dispose(); conexao.Close(); conexao.Dispose(); } }
diogom Posted April 12, 2012 at 10:01 AM Author Report #448736 Posted April 12, 2012 at 10:01 AM já passa pelo codigo todo, mas, não aparece a gridview. Tenho a tabela com dados.
Caça Posted April 12, 2012 at 10:07 AM Report #448739 Posted April 12, 2012 at 10:07 AM Os Bindings estão bem feitos? Pedro Martins Não respondo a duvidas por PM
diogom Posted April 12, 2012 at 11:04 AM Author Report #448746 Posted April 12, 2012 at 11:04 AM Já resolvi. obrg 🙂
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