none
what am i missing in this RRS feed

  • Question

  • I have a button on a childform that is to show all the records from tblGlossary.  A stored proc is what is used and shows in the code below.  The code below is what is behind the button click.  I know that it works as I had messageboxes placed along the way and in the 'for' part it kept showing until done.  So the connection is there, the stored proc is used, etc.  The issue is nothing is showing in the datagridview.  Am I missing something in the code below or something I need to do with the datagridview? 

    Thanks...John

    string connStr = null;
    SqlConnection conn;
    SqlDataAdapter adapter;
    SqlCommand command = new SqlCommand();
    DataSet ds = new DataSet();

    int i = 0;

    connStr = ConfigurationManager.ConnectionStrings["BOSSConnectionString"].ConnectionString;
    conn = new SqlConnection(connStr);
    conn.Open();

    command.Connection = conn;
    command.CommandType = CommandType.StoredProcedure;
    command.CommandText = "SEL_Glossary_ALL";

    adapter = new SqlDataAdapter(command);
    adapter.Fill(ds);

    for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
    {
        dataGlossaryGridView.DataSource = ds;
    }

    conn.Close();

    Tuesday, November 13, 2012 2:58 AM

Answers

  • I got it.  I went with a datatable from dataset.  I replaced a few lines with the following and now it works fine.

    Thanks....John

    DataTable tbl = new DataTable();
    adapter.Fill(tbl);

    dataGlossaryGridView.DataSource = tbl;

    Tuesday, November 13, 2012 3:38 PM

All replies

  • Hi Friend,
      You migh need to call dataGlossaryGridView.DataBind() method after you assign the datasource.


    -- Thanks Ajith R Nair

    Tuesday, November 13, 2012 8:43 AM
  • Thanks for the reply.  You might be right but in the windows form Databind() is not available.  I get the 'does not contain a definition for Databind could be found (are you missing a using directive or an assembly reference?)'.  Below are listed what is at the top of the coding page.  I don't think I'm missing anything there.  What about the datagridview itself?

    Thanks...John

    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;
    using System.Configuration;
    using System.Xml;
    using System.Data.Common;

    Tuesday, November 13, 2012 3:23 PM
  • I got it.  I went with a datatable from dataset.  I replaced a few lines with the following and now it works fine.

    Thanks....John

    DataTable tbl = new DataTable();
    adapter.Fill(tbl);

    dataGlossaryGridView.DataSource = tbl;

    Tuesday, November 13, 2012 3:38 PM