Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Guys ! i have a issue i hope you help me
i want to display dataset value in textbox here am using code
please check it
C#
private void timer2_Tick(object sender, EventArgs e)
        {
            string connStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Restaurant.accdb;Persist Security Info=False;";
            //string query = "SELECT [Column3] As [Table No],SUM(Column1) As Price,[Receipt No],Date From Total Group By [Column3],[Receipt No],Date";
            //string query = "Select Column3 As [Table No],SUM(Column1) As [Price],[Receipt No],Date FROM Total GROUP BY [Column3],[Receipt No],Date";
            string query = "Select Report From Total";
            using (OleDbConnection conn = new OleDbConnection(connStr))
            {
                using (OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn))
                {
                    conn.Open();
                    DataSet ds = new DataSet();
                    if (ds != null)
                    {
                        adapter.Fill(ds);
                        textBox63.Text = ds.Tables[0].ToString();
                        conn.Close();
                        if (dataGridView1.Rows.Count == 1)
                        {
                            MessageBox.Show("Data is Empty", "RETURN FORM", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            this.Close();
                        }
                        else
                        {
                         //   textBox63.Text = ds.Tables[0].ToString();
                        }
                    }
                }
            }

out and give me best solution of this problem

What I have tried:

private void timer2_Tick(object sender, EventArgs e)
{
string connStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Restaurant.accdb;Persist Security Info=False;";
string query = "Select Sum(Report) From Total";
using (OleDbConnection conn = new OleDbConnection(connStr))
{
using (OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn))
{
conn.Open();
DataSet ds = new DataSet();
if (ds != null)
{
adapter.Fill(ds);
textBox63.Text = ds.Tables[0].ToString();
conn.Close();
}
}
}
Posted
Updated 24-Jul-16 20:29pm
Comments
BillWoodruff 24-Jul-16 17:07pm    
You need to get most of that code outside the Timer 'Tick event, and then only perform the query in the 'Tick event.
Member 9983063 24-Jul-16 17:17pm    
what is tick event?
ZurdoDev 24-Jul-16 18:59pm    
1. Reply to the comment so that the user is notified instead of adding a new comment to your own question.
2. What is your question?

A few pointers.

1. As Bill has stated do not put the data retrieval code in the Timer
events, but place it in a separate method.

2. Ensure the timer is disabled after it has run otherwise the code will rerun with every timer interval (unless that is the functionality you are after)

3.
C#
textBox63.Text = ds.Tables[0].ToString();
The ds.Tables[)].Tostring() is trying to return the tables string, not the row value. Use ds.Tables[0].Rows[0]["Report"].ToString() to retrieve the report value

4. Find a tutorial on the subject and follow the examples they use.
 
Share this answer
 
If you want to display the value of a particular column then you have to use

C#
textBox63.Text = ds.Tables[0].Rows[0]["ColumnName"].ToString();


OR

C#
textBox63.Text = ds.Tables[0].Rows[0][ColumnIndex].ToString();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900