ali mr

ali mr

  • NA
  • 1
  • 1.8k

Working with classes

Jan 7 2012 6:37 AM
Hello Everyone here,
I m still beginer in ASP.net. I have a data base file called products which has the following fields 
 
[Productid] [int] IDENTITY(1,1) NOT NULL,
       
[Productname] [varchar](50) NULL,
       
[Descs] [varchar](50) NULL,
       
[Quantity] [int] NULL,
       
[amountvalue] [float] NULL,
       
[productpendingamount] [float] NULL,
 CONSTRAINT
[PK_Products] PRIMARY KEY CLUSTERED

and I have made a class which will retrive the data from the database. I want to write the product number in the field of product name and once I press enrer the data will be displayed in the textboxes for the product name, product desc and so on. the following code I have made for both class file and the calling code for this class.

public void showdproductetails (int a, string b, string c, int d, float e, float f)    {       
string strc = ConfigurationManager.ConnectionStrings["Products"].ConnectionString;   
SqlConnection con = new SqlConnection(strc);   
    con.Open();       
SqlCommand cmd = new SqlCommand();   
    cmd.Connection = con; 
      cmd.CommandText = "select Productname, Descs, Quantity, amountvalue, productpendingamount from Products where productid = @a";   
    cmd.Parameters.AddWithValue("a", a);     
  SqlDataReader rd = cmd.ExecuteReader();     
  while (rd.Read())     
  {            b = rd.GetString(0);   
        c = rd.GetString(1);         
  d = rd.GetInt32(2);       
    e = rd.GetFloat(3);       
    f = rd.GetFloat(4);     
  }


the follwing code is for the calling of the class:
Products objfind = new Products();        objfind.showdproductetails(int.Parse(TextBox1.Text), TextBox2.Text, TextBox3.Text, int.Parse(TextBox4.Text), float.Parse(TextBox5.Text), float.Parse(TextBox6.Text));

Answers (1)