Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public string Insert_tmpStock_Card(tmp_Stock_CardBEL scbel, string Prod_code)
      {

          //Insert_tmpStock_Card
          if (cn.State != ConnectionState.Open)
              cn.Open();
          cmd.Connection = cn;

          cmd = new SqlCommand("SP_StockItem_Insert_tmpStock_Card", cn);
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.AddWithValue("@comp_id", scbel.Comp_id);
          cmd.Parameters.AddWithValue("@uid", scbel.Uid);
          cmd.Parameters.AddWithValue("@prod_code", Prod_code);
          dr = cmd.ExecuteReader();
          while (dr.Read())
          {
              tmp = dr["type"].ToString();
              transid = dr["sid"].ToString();
          }
          dr.Close();
          return tmp;


      }



here i want two values tmp,transid in presentation layer,but i can.t returning two values,only tmp value is getting,so plz help me to call two values
Posted
Updated 11-Sep-14 18:42pm
v2
Comments
Prasad Avunoori 12-Sep-14 0:46am    
Hi Navya,

I have posted two ways one with out params and two with Key value pair in my solution below.
IpsitaMishra 12-Sep-14 0:46am    
It is not possible to return 2 values from a method,but you can try other alternatives
1.Create 1 class with 2 properties and return that class from the method.
2.You can return 1 value and set 1 out parameters.

Hope this help you.
navya chowdary 12-Sep-14 0:52am    
you have any example like that
george4986 12-Sep-14 1:03am    
where u declare tmp,transid?
ur function return type is string?
plz post the calling code if possible
navya chowdary 12-Sep-14 1:21am    
yes my function return type is "string",it declared string tmp="",transid="" in DAL,
IN PRESENTATION LAYER
tmp= skbll.Insert_tmpStock_Card(scbel, prodcode,tmp,transid);
transid= skbll.Insert_tmpStock_Card(scbel, prodcode,tmp,transid);

C#
public void Insert_tmpStock_Card(tmp_Stock_CardBEL scbel, string Prod_code,out  string tmp, out string transid)
      {

          //Insert_tmpStock_Card
          if (cn.State != ConnectionState.Open)
              cn.Open();
          cmd.Connection = cn;

          cmd = new SqlCommand("SP_StockItem_Insert_tmpStock_Card", cn);
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.AddWithValue("@comp_id", scbel.Comp_id);
          cmd.Parameters.AddWithValue("@uid", scbel.Uid);
          cmd.Parameters.AddWithValue("@prod_code", Prod_code);
          dr = cmd.ExecuteReader();
          while (dr.Read())
          {
              tmp = dr["type"].ToString();
              transid = dr["sid"].ToString();
          }
          dr.Close();
          
      }


Call the above method as below.

ClassName objClassName = new ClassName();

objClassName.Insert_tmpStock_Card(tmp_Stock_CardBEL scbel, Prod_code,out tmp, out transid)

After calling this method, you will be having two expected values in tmp, transid.

That's it!
 
Share this answer
 
v3
Comments
navya chowdary 12-Sep-14 0:49am    
i want it for 3 tier architecture,and it read two values from stored procedure
Prasad Avunoori 12-Sep-14 0:55am    
View my updated solution.
navya chowdary 12-Sep-14 0:59am    
what is "ClassName" here
Prasad Avunoori 12-Sep-14 1:30am    
In your presentation layer do like this:

string tmp,transid;
skbll.Insert_tmpStock_Card(scbel, prodcode,tmp,transid);

Don't call the method twice.
navya chowdary 12-Sep-14 1:41am    
thanks for spending time for my sloution...
Ignoring other issues with your code, lets give a little tweak to your code gives you what you want.
C#
public void Insert_tmpStock_Card(tmp_Stock_CardBEL scbel, string Prod_code, out string type, out string transid)
      {
 
          //Insert_tmpStock_Card
          if (cn.State != ConnectionState.Open)
              cn.Open();
          cmd.Connection = cn;
 
          cmd = new SqlCommand("SP_StockItem_Insert_tmpStock_Card", cn);
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.AddWithValue("@comp_id", scbel.Comp_id);
          cmd.Parameters.AddWithValue("@uid", scbel.Uid);
          cmd.Parameters.AddWithValue("@prod_code", Prod_code);
          dr = cmd.ExecuteReader();
          while (dr.Read())
          {
              type = dr["type"].ToString();
              transid = dr["sid"].ToString();
          }
          dr.Close();
       }
}


If you can understand this is same what Prasad has said in Solution 1
 
Share this answer
 
Comments
navya chowdary 12-Sep-14 1:06am    
what is difference between,string and out string
ur return type is string,its easy to use string functions
replace
C#
return tmp;

in ur code with
C#
return tmp+"~"+transid;

use split function of string to extract values
IN PRESENTATION LAYER (calling side)
C#
string result=skbll.Insert_tmpStock_Card(scbel, prodcode, tmp, transid).ToString();
tmp = result.Split('~')[0].ToString();
transid = result.Split('~')[1].ToString();
 
Share this answer
 
v2
Comments
navya chowdary 12-Sep-14 1:39am    
thank you,can i use this for any number of values
george4986 12-Sep-14 1:46am    
it is an easy fix ,string value can store upto 2 Gb.
refer this link
http://stackoverflow.com/questions/810797/which-is-better-return-value-or-out-parameter

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