locked
Displaying Unknown number of columns based on a query statement RRS feed

  • Question

  • User-606362864 posted

    Hello,

    I am new to C# and ASP.NET.  I am using VS 2008.  I have been trying to build a simple web page that would query iSeries using a DSN.  I was able to get the connection made to the iSeries and get the data back.  I am able to displaying data returned if I request data in three columns.

    For example, SELECT FName, LName, Town FROM Customer.

    What I have on the ASP page is a text field where user can give the connection string Dsn=MYDSNNAME;uid=USERNAME;pwd=PASSWORD.  A text field where a query can be written and a submitt button.

    When submit button is clicked following code is executed:

                String connectionString = txtConString.Text;
                OdbcConnection conn = new OdbcConnection(connectionString);
                string query = txtQuery.Text;
                conn.Open();
                string queryString = query;
                OdbcCommand command = new OdbcCommand(queryString, conn);
                OdbcDataReader rs = command.ExecuteReader();

                GridView1.DataSource = rs;
                GridView1.DataBind();

                conn.Close();

    Any assistance would be appreciated.

    Wednesday, February 22, 2012 6:50 PM

Answers

  • User17557945 posted

    Have you checked the value of GridView1.Rows.Count(after the statement GridView1.DataBind()) while debugging? Make sure that the value>0.Otherwise, no data will be displayed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 22, 2012 11:59 PM

All replies

  • User-1407477457 posted

    The code you have should accomplish what you say you want.  What happens when you run it with a query that returns a different number of columns?

    Wednesday, February 22, 2012 7:16 PM
  • User-606362864 posted

    Thanks for the quick response.  Nothing seems to happen. I don't get an execptions and no data is displayed.  I can see that the query is executing when I use a debuger.

    Wednesday, February 22, 2012 7:53 PM
  • User17557945 posted

    Have you checked the value of GridView1.Rows.Count(after the statement GridView1.DataBind()) while debugging? Make sure that the value>0.Otherwise, no data will be displayed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 22, 2012 11:59 PM
  • User-606362864 posted

    Thank you Kalpana_p01.  That was the issue.  I was not getting any results back. I changed the query and I got results.  I got the results on the web page.

    Thursday, February 23, 2012 2:39 PM
  • User17557945 posted

    Please mark my earlier reply as answer:) since it solved ur issue

    Thursday, February 23, 2012 11:49 PM