Trouble obtaining database table values...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gggram2000
    New Member
    • Nov 2007
    • 97

    #1

    Trouble obtaining database table values...

    Hi, I need some suggestions...

    I have created a form in visual studio 2005 in which a user chooses between to dates. I placed two dateTimePickers and a View Button. When the user clicks the view button, I have a sql command that is supposed to retrieve all values from both table 'Guest' and table 'Sales' in sql server 2005.
    My code looks like this:
    Code:
                SqlConnection dbConnection = new SqlConnection(xmldb);
                SqlCommand cmd = new SqlCommand(" SELECT * From Guest g, Sales s Where s.Date >= '" + dateTimePicker1.Value + "' And s.Date <= '" + dateTimePicker2.Value + "' Order By s.Date ", dbConnection1);                                    
                cmd.CommandType = CommandType.Text;
                SqlDataAdapter da = new SqlDataAdapter(cmd);             
                DataTable dt = new DataTable();
                da.Fill(dt);
                textBox1.Text = dt.Rows[0][0].ToString();
    My obvious problem here is that since I want all values from both tables, I don't know what other process I should use. For example:
    textBox1.Text = dt.Rows[0][0].ToString(); will not work because it will only return the number of rows...The other problem is that I have tested the function with actual dates and it works fine, so it has something to do with dateTimePickers 1.Text or something else...I would really appreciate some suggestions as to how to obtains all values and details found on those two tables between those two dates and on what would be the easiest way to display it.Thanks.
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Before executing the query, print the query. This way, you will be able to see if the query is OK or not.

    Are you using VB?

    Comment

    • gggram2000
      New Member
      • Nov 2007
      • 97

      #3
      Originally posted by mwasif
      Before executing the query, print the query. This way, you will be able to see if the query is OK or not.

      Are you using VB?
      No I am using c-sharp. When I run run the program I only get the number of rows gathered from the two tables. What do you mean by printing the query?

      Comment

      • gggram2000
        New Member
        • Nov 2007
        • 97

        #4
        Ok, since i'm not sure how to obtain all values (Select *) I'ved selected all the columns that I really need, my code looks like this:
        Code:
        textBox1.Text = dt1.Rows[0]["GuestFirstName"].ToString();
        and this successfully gives me the name of the person. Now my question is this: How can I make all columns display on the same textbox, something like this:
        Code:
        textBox1.Text = dt1.Rows[0]["C1"]["C2"]["C3"]["C4"].ToString();
        with all the columns that I want...Please let me know

        Comment

        • gggram2000
          New Member
          • Nov 2007
          • 97

          #5
          Ok, since i'm not sure how to obtain all values (Select *) I'ved selected all the columns that I really need, my code looks like this:
          Code:
          textBox1.Text = dt1.Rows[0]["GuestFirstName"].ToString();
          and this successfully gives me the name of the person. Now my question is this: How can I make all columns display on the same textbox, something like this:
          Code:
          textBox1.Text = dt1.Rows[0]["C1"].ToString();
          textBox1.Text = dt1.Rows[0]["C2"].ToString();
          textBox1.Text = dt1.Rows[0]["C3"].ToString();
          //And so fort...but i want the textbox to expand so it scrolls to the side...
          with all the columns that I want...Please let me know

          Comment

          • gggram2000
            New Member
            • Nov 2007
            • 97

            #6
            Ok I do get all the rows with that method, the only issue is that it's too tedious when it comes to hundreds of sales in between those dates. I would need to enter each row a hundred times and still don't know if it will be spacious enough to display the info in. Is there an easier method to display all the info? Anyone??

            Comment

            • mwasif
              Recognized Expert Contributor
              • Jul 2006
              • 802

              #7
              Moved to .Net Forum.

              Comment

              Working...