How to get many field on the Query of webserviceHow do I calculate someone's age in C#?How do I enumerate an enum in C#?What is the difference between a field and a property?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Get int value from enum in C#C# SQL Columns into ComboBoxHow do I generate a random int number?c# closing sqlconnection and sqldatareader or not?What is a NullReferenceException, and how do I fix it?Error : There is already an open DataReader associated with this Command which must be closed first
Extending Kan fibrations, without using minimal fibrations
How do I compare the result of "1d20+x, with advantage" to "1d20+y, without advantage", assuming x < y?
What is wrong with my code? RGB potentiometer
Remove color cast in darktable?
Removing all characters except digits from clipboard
Is it nonsense to say B -> [A -> B]?
How to get the IP of a user who executed a command?
Program for finding longest run of zeros from a list of 100 random integers which are either 0 or 1
Renting a house to a graduate student in my department
Has there been evidence of any other gods?
When do you stop "pushing" a book?
Why do unstable nuclei form?
Why does the Earth follow an elliptical trajectory rather than a parabolic one?
Why did they go to Dragonstone?
What does this quote in Small Gods refer to?
How can I avoid subordinates and coworkers leaving work until the last minute, then having no time for revisions?
Is every story set in the future "science fiction"?
We are two immediate neighbors who forged our own powers to form concatenated relationship. Who are we?
Is there an application which does HTTP PUT?
Company threw a surprise party for the CEO, 3 weeks later management says we have to pay for it, do I have to?
Is it bad writing or bad story telling if first person narrative contains more information than the narrator knows?
Which other programming languages apart from Python and predecessor are out there using indentation to define code blocks?
Was the Highlands Ranch shooting the 115th mass shooting in the US in 2019
Why do the non-leaf Nodes of Merkle tree need to be hashed?
How to get many field on the Query of webservice
How do I calculate someone's age in C#?How do I enumerate an enum in C#?What is the difference between a field and a property?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Get int value from enum in C#C# SQL Columns into ComboBoxHow do I generate a random int number?c# closing sqlconnection and sqldatareader or not?What is a NullReferenceException, and how do I fix it?Error : There is already an open DataReader associated with this Command which must be closed first
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am making a web service get data from sql server. I need to get many fields from the sql server, but I can only get one field, which is the Currancy Name
namespace WebApplication2
public class DataHelper
public static string GetCurrency(string currencyCode)
string currencyName = "";
SqlConnection con = new SqlConnection(@"Data Source=WEB3SHAREPOINT;Initial Catalog=WSS_Search_WEB3;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select PO_NUMBER,PO_STATUS from View_1 where PO_HEADER_ID ='" + currencyCode.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
currencyName = dr["PO_NUMBER"].ToString();
dr.Close();
con.Close();
return currencyName;
I need to get the PO_Number & PO Status from the Query
c# web-services
|
show 7 more comments
I am making a web service get data from sql server. I need to get many fields from the sql server, but I can only get one field, which is the Currancy Name
namespace WebApplication2
public class DataHelper
public static string GetCurrency(string currencyCode)
string currencyName = "";
SqlConnection con = new SqlConnection(@"Data Source=WEB3SHAREPOINT;Initial Catalog=WSS_Search_WEB3;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select PO_NUMBER,PO_STATUS from View_1 where PO_HEADER_ID ='" + currencyCode.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
currencyName = dr["PO_NUMBER"].ToString();
dr.Close();
con.Close();
return currencyName;
I need to get the PO_Number & PO Status from the Query
c# web-services
Where is the code?
– Crowcoder
Mar 23 at 10:36
on the comment after the detalis
– M7md Babers
Mar 23 at 11:35
stackoverflow.com/q/55312498/11246623
– M7md Babers
Mar 23 at 11:36
so if you need po status just repeat the same steps for po number? else than that what is the problem I can not realy understand what you want?
– maytham-ɯɐɥʇʎɐɯ
Mar 23 at 11:51
1
Do the same forPO_STATUS
as you do forPO_NUMBER
. Did you write that code or are you maintaining it? No offense but it seems pretty obvious you are only extracting one field.
– Crowcoder
Mar 23 at 11:51
|
show 7 more comments
I am making a web service get data from sql server. I need to get many fields from the sql server, but I can only get one field, which is the Currancy Name
namespace WebApplication2
public class DataHelper
public static string GetCurrency(string currencyCode)
string currencyName = "";
SqlConnection con = new SqlConnection(@"Data Source=WEB3SHAREPOINT;Initial Catalog=WSS_Search_WEB3;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select PO_NUMBER,PO_STATUS from View_1 where PO_HEADER_ID ='" + currencyCode.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
currencyName = dr["PO_NUMBER"].ToString();
dr.Close();
con.Close();
return currencyName;
I need to get the PO_Number & PO Status from the Query
c# web-services
I am making a web service get data from sql server. I need to get many fields from the sql server, but I can only get one field, which is the Currancy Name
namespace WebApplication2
public class DataHelper
public static string GetCurrency(string currencyCode)
string currencyName = "";
SqlConnection con = new SqlConnection(@"Data Source=WEB3SHAREPOINT;Initial Catalog=WSS_Search_WEB3;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select PO_NUMBER,PO_STATUS from View_1 where PO_HEADER_ID ='" + currencyCode.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
currencyName = dr["PO_NUMBER"].ToString();
dr.Close();
con.Close();
return currencyName;
I need to get the PO_Number & PO Status from the Query
c# web-services
c# web-services
edited Mar 23 at 11:51
maytham-ɯɐɥʇʎɐɯ
11.4k75070
11.4k75070
asked Mar 23 at 9:49
M7md BabersM7md Babers
44
44
Where is the code?
– Crowcoder
Mar 23 at 10:36
on the comment after the detalis
– M7md Babers
Mar 23 at 11:35
stackoverflow.com/q/55312498/11246623
– M7md Babers
Mar 23 at 11:36
so if you need po status just repeat the same steps for po number? else than that what is the problem I can not realy understand what you want?
– maytham-ɯɐɥʇʎɐɯ
Mar 23 at 11:51
1
Do the same forPO_STATUS
as you do forPO_NUMBER
. Did you write that code or are you maintaining it? No offense but it seems pretty obvious you are only extracting one field.
– Crowcoder
Mar 23 at 11:51
|
show 7 more comments
Where is the code?
– Crowcoder
Mar 23 at 10:36
on the comment after the detalis
– M7md Babers
Mar 23 at 11:35
stackoverflow.com/q/55312498/11246623
– M7md Babers
Mar 23 at 11:36
so if you need po status just repeat the same steps for po number? else than that what is the problem I can not realy understand what you want?
– maytham-ɯɐɥʇʎɐɯ
Mar 23 at 11:51
1
Do the same forPO_STATUS
as you do forPO_NUMBER
. Did you write that code or are you maintaining it? No offense but it seems pretty obvious you are only extracting one field.
– Crowcoder
Mar 23 at 11:51
Where is the code?
– Crowcoder
Mar 23 at 10:36
Where is the code?
– Crowcoder
Mar 23 at 10:36
on the comment after the detalis
– M7md Babers
Mar 23 at 11:35
on the comment after the detalis
– M7md Babers
Mar 23 at 11:35
stackoverflow.com/q/55312498/11246623
– M7md Babers
Mar 23 at 11:36
stackoverflow.com/q/55312498/11246623
– M7md Babers
Mar 23 at 11:36
so if you need po status just repeat the same steps for po number? else than that what is the problem I can not realy understand what you want?
– maytham-ɯɐɥʇʎɐɯ
Mar 23 at 11:51
so if you need po status just repeat the same steps for po number? else than that what is the problem I can not realy understand what you want?
– maytham-ɯɐɥʇʎɐɯ
Mar 23 at 11:51
1
1
Do the same for
PO_STATUS
as you do for PO_NUMBER
. Did you write that code or are you maintaining it? No offense but it seems pretty obvious you are only extracting one field.– Crowcoder
Mar 23 at 11:51
Do the same for
PO_STATUS
as you do for PO_NUMBER
. Did you write that code or are you maintaining it? No offense but it seems pretty obvious you are only extracting one field.– Crowcoder
Mar 23 at 11:51
|
show 7 more comments
2 Answers
2
active
oldest
votes
As I understand you need to return not only PO_NUMBER, but also PO_STATUS, and as I understand you want to return both values.
I suggest you make model that represent what you want to return.
So for that we make a model class call it for instance POModel:
public class POModel
public string currencyName get; set; // PO_Number
public string statusName get; set; // PO_Status
Than fetch the values from SQL as you did and return object in stead of string.
Here would you final code looks like, of course naming and all the stuff you can change the way if fits best:
public class DataHelper
public static POModel GetCurrency(string currencyCode)
//string currencyName = "";
var poModel = new POModel();
SqlConnection con = new SqlConnection(@"Data Source=WEB3SHAREPOINT;Initial Catalog=WSS_Search_WEB3;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select PO_NUMBER,PO_STATUS from View_1 where PO_HEADER_ID ='" + currencyCode.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
poModel.currencyName = dr["PO_NUMBER"].ToString();
poModel.statusName = dr["PO_STATUS"].ToString();
dr.Close();
con.Close();
//return currencyName;
return poModel;
public class POModel
public string currencyName get; set;
public string statusName get; set;
add a comment |
One option is to return an array that contains the two values. Notice string[]
:
public static string[] GetCurrency(string currencyCode)
Similar to how you declared string currencyName = "";
, instead make an array variable:
string[] poData = new string[2];
Since this looks like it should return a single row, I would not loop. Just do a Read()
:
dr.Read();
poData[0] = dr["PO_NUMBER"].ToString(); //poData[] will have to be declared in your method
poData[1] = dr["PO_STATUS"].ToString();
....
return poData;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312498%2fhow-to-get-many-field-on-the-query-of-webservice%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As I understand you need to return not only PO_NUMBER, but also PO_STATUS, and as I understand you want to return both values.
I suggest you make model that represent what you want to return.
So for that we make a model class call it for instance POModel:
public class POModel
public string currencyName get; set; // PO_Number
public string statusName get; set; // PO_Status
Than fetch the values from SQL as you did and return object in stead of string.
Here would you final code looks like, of course naming and all the stuff you can change the way if fits best:
public class DataHelper
public static POModel GetCurrency(string currencyCode)
//string currencyName = "";
var poModel = new POModel();
SqlConnection con = new SqlConnection(@"Data Source=WEB3SHAREPOINT;Initial Catalog=WSS_Search_WEB3;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select PO_NUMBER,PO_STATUS from View_1 where PO_HEADER_ID ='" + currencyCode.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
poModel.currencyName = dr["PO_NUMBER"].ToString();
poModel.statusName = dr["PO_STATUS"].ToString();
dr.Close();
con.Close();
//return currencyName;
return poModel;
public class POModel
public string currencyName get; set;
public string statusName get; set;
add a comment |
As I understand you need to return not only PO_NUMBER, but also PO_STATUS, and as I understand you want to return both values.
I suggest you make model that represent what you want to return.
So for that we make a model class call it for instance POModel:
public class POModel
public string currencyName get; set; // PO_Number
public string statusName get; set; // PO_Status
Than fetch the values from SQL as you did and return object in stead of string.
Here would you final code looks like, of course naming and all the stuff you can change the way if fits best:
public class DataHelper
public static POModel GetCurrency(string currencyCode)
//string currencyName = "";
var poModel = new POModel();
SqlConnection con = new SqlConnection(@"Data Source=WEB3SHAREPOINT;Initial Catalog=WSS_Search_WEB3;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select PO_NUMBER,PO_STATUS from View_1 where PO_HEADER_ID ='" + currencyCode.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
poModel.currencyName = dr["PO_NUMBER"].ToString();
poModel.statusName = dr["PO_STATUS"].ToString();
dr.Close();
con.Close();
//return currencyName;
return poModel;
public class POModel
public string currencyName get; set;
public string statusName get; set;
add a comment |
As I understand you need to return not only PO_NUMBER, but also PO_STATUS, and as I understand you want to return both values.
I suggest you make model that represent what you want to return.
So for that we make a model class call it for instance POModel:
public class POModel
public string currencyName get; set; // PO_Number
public string statusName get; set; // PO_Status
Than fetch the values from SQL as you did and return object in stead of string.
Here would you final code looks like, of course naming and all the stuff you can change the way if fits best:
public class DataHelper
public static POModel GetCurrency(string currencyCode)
//string currencyName = "";
var poModel = new POModel();
SqlConnection con = new SqlConnection(@"Data Source=WEB3SHAREPOINT;Initial Catalog=WSS_Search_WEB3;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select PO_NUMBER,PO_STATUS from View_1 where PO_HEADER_ID ='" + currencyCode.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
poModel.currencyName = dr["PO_NUMBER"].ToString();
poModel.statusName = dr["PO_STATUS"].ToString();
dr.Close();
con.Close();
//return currencyName;
return poModel;
public class POModel
public string currencyName get; set;
public string statusName get; set;
As I understand you need to return not only PO_NUMBER, but also PO_STATUS, and as I understand you want to return both values.
I suggest you make model that represent what you want to return.
So for that we make a model class call it for instance POModel:
public class POModel
public string currencyName get; set; // PO_Number
public string statusName get; set; // PO_Status
Than fetch the values from SQL as you did and return object in stead of string.
Here would you final code looks like, of course naming and all the stuff you can change the way if fits best:
public class DataHelper
public static POModel GetCurrency(string currencyCode)
//string currencyName = "";
var poModel = new POModel();
SqlConnection con = new SqlConnection(@"Data Source=WEB3SHAREPOINT;Initial Catalog=WSS_Search_WEB3;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select PO_NUMBER,PO_STATUS from View_1 where PO_HEADER_ID ='" + currencyCode.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
poModel.currencyName = dr["PO_NUMBER"].ToString();
poModel.statusName = dr["PO_STATUS"].ToString();
dr.Close();
con.Close();
//return currencyName;
return poModel;
public class POModel
public string currencyName get; set;
public string statusName get; set;
answered Mar 23 at 12:03
maytham-ɯɐɥʇʎɐɯmaytham-ɯɐɥʇʎɐɯ
11.4k75070
11.4k75070
add a comment |
add a comment |
One option is to return an array that contains the two values. Notice string[]
:
public static string[] GetCurrency(string currencyCode)
Similar to how you declared string currencyName = "";
, instead make an array variable:
string[] poData = new string[2];
Since this looks like it should return a single row, I would not loop. Just do a Read()
:
dr.Read();
poData[0] = dr["PO_NUMBER"].ToString(); //poData[] will have to be declared in your method
poData[1] = dr["PO_STATUS"].ToString();
....
return poData;
add a comment |
One option is to return an array that contains the two values. Notice string[]
:
public static string[] GetCurrency(string currencyCode)
Similar to how you declared string currencyName = "";
, instead make an array variable:
string[] poData = new string[2];
Since this looks like it should return a single row, I would not loop. Just do a Read()
:
dr.Read();
poData[0] = dr["PO_NUMBER"].ToString(); //poData[] will have to be declared in your method
poData[1] = dr["PO_STATUS"].ToString();
....
return poData;
add a comment |
One option is to return an array that contains the two values. Notice string[]
:
public static string[] GetCurrency(string currencyCode)
Similar to how you declared string currencyName = "";
, instead make an array variable:
string[] poData = new string[2];
Since this looks like it should return a single row, I would not loop. Just do a Read()
:
dr.Read();
poData[0] = dr["PO_NUMBER"].ToString(); //poData[] will have to be declared in your method
poData[1] = dr["PO_STATUS"].ToString();
....
return poData;
One option is to return an array that contains the two values. Notice string[]
:
public static string[] GetCurrency(string currencyCode)
Similar to how you declared string currencyName = "";
, instead make an array variable:
string[] poData = new string[2];
Since this looks like it should return a single row, I would not loop. Just do a Read()
:
dr.Read();
poData[0] = dr["PO_NUMBER"].ToString(); //poData[] will have to be declared in your method
poData[1] = dr["PO_STATUS"].ToString();
....
return poData;
edited Mar 23 at 12:42
answered Mar 23 at 12:05
CrowcoderCrowcoder
7,28822433
7,28822433
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312498%2fhow-to-get-many-field-on-the-query-of-webservice%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Where is the code?
– Crowcoder
Mar 23 at 10:36
on the comment after the detalis
– M7md Babers
Mar 23 at 11:35
stackoverflow.com/q/55312498/11246623
– M7md Babers
Mar 23 at 11:36
so if you need po status just repeat the same steps for po number? else than that what is the problem I can not realy understand what you want?
– maytham-ɯɐɥʇʎɐɯ
Mar 23 at 11:51
1
Do the same for
PO_STATUS
as you do forPO_NUMBER
. Did you write that code or are you maintaining it? No offense but it seems pretty obvious you are only extracting one field.– Crowcoder
Mar 23 at 11:51