Hi,

I am working on a project in that I want to dispaly the avablible quantity from database. I have write some code for that code is working. but It display entier data from frist row to last. I want to display only particular item avaliable quantity. can any one help me to slove the problem please....

Here is my code:

string val = textBox2.Text;
            string contr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\praj\\sports shop\\database.mdb";
            OleDbConnection cn = new OleDbConnection();
            cn.ConnectionString = contr;
            cn.Open();
            string str = "select avbqut from ava  where itnm=?val ";

            OleDbCommand  cmd = new  OleDbCommand(str, cn);
            cmd.CommandType = CommandType.Text;
            OleDbParameter sql;
            sql = cmd.Parameters.Add("?val",OleDbType.VarChar, 15);
            sql.Value = val;

Please help me....

Recommended Answers

All 3 Replies

use ExecuteScalar it return only one cell value


i.e
object obj=cmd.ExecuteScalar();
int quantity=int.parse(obj);

Thank for reply

But I want to show last save data when user sale some product then the avaliable quantity - slod quantity = remaning quantity. and now remanning quantity = avaliable quantity now avaliable quantity is change. I want to show that last saved avaliable quentity of that particular product.

//Dear Friend Check this Code i hope you access your destination

  string sql = "select quantity from databaseName"; 

       OleDbCommand cmd = new OleDbCommand(sql, conn);

   int LastQty; 
         OleDbDataReader rd = cmd.ExecuteReader();
           while (rd.Read())
            {
                LastQty = int.parse(rd["quantity"]);
           }


 //after end of while you will find last value of this column or data

                Label1.Text =LastQty.ToString()  ;  <<this is your output

            conn.Close();
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.