hey friends i need to retrive data in textbox...

here is the detail information...

A class has been created:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace databaseR
{
    class data
    {
        public SqlConnection dbCon;
        public SqlCommand dbCmd;
        public SqlDataAdapter dbAdptr;
        public SqlDataReader dbRdr;

        public void dbConnect()
        {
            string con = @"Data Source=PRAYAG-PC\SQLEXPRESS ; Initial catalog =Practice ; User ID=sa ; Password=sys ";

            dbCon = new SqlConnection(con);
            dbCon.Open();
        }

        public void dbFetch(string cmd)
        {
            dbCmd = new SqlCommand(cmd, dbCon);
            dbRdr = dbCmd.ExecuteReader();
        }

    }
}

The main form :

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;


namespace databaseR
{
    public partial class frmRetrival : Form
    {
        public frmRetrival()
        {
            InitializeComponent();
        }
        data db;

        private void frmRetrival_Load(object sender, EventArgs e)
        {

        }

        private void btnRetrive_Click(object sender, EventArgs e)
        {

            try
            {
                db = new data();
                db.dbConnect();
                db.dbFetch("select sum(QUANTITY) as total from Three");
                if (db.dbRdr.Read())
                {
                   [COLOR="Green"]/* DON'T KNOW WHAT TO DO ! */[/COLOR]
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                db.dbCon.Close();
            }
        }
    }
}

Now in IF condition i don't know what to write so that a total quantity will be displayed..

PLEASE HELP ITS URGENT.

Thanks in advance

if (db.dbRdr.Read())
{
    textBox1.Text = (string)dbRdr[0];
}

YOu simply have to specify the type of tghe db`s column to the reader, and pass th value to the variable - in your case this is the control textBox1.
Hope it helps,
Mitja

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.