0

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....

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by hassan12345
0

use ExecuteScalar it return only one cell value


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

0

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.

0
//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();

Edited by Dani: Formatting fixed

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.