The given should return A,B that is two rows because both
accountnames A and B have the same user_Id=1 but it is only returning
A when I performed the op. MessageBox.Show ("AccountNames: " +
Object.ToString () );
[WebMethod]
public Object GetAccountNames (string User_Id)
{
//string AccountNames;
Object AccountNames;
// create a Command,Connect ion and Reader object
System.Data.Sql Client.SqlConne ction sqlConnection1 =
new System.Data.Sql Client.SqlConne ction(connectio nString);
System.Data.Sql Client.SqlComma nd cmd = new
System.Data.Sql Client.SqlComma nd();
//Object returnValue;
// Search for the pincode
cmd.CommandText = "SELECT acc_name FROM Account_Informa tion
where user_id='" + User_Id + "'";
cmd.CommandType = CommandType.Tex t;
cmd.Connection = sqlConnection1;
sqlConnection1. Open();
AccountNames = cmd.ExecuteScal ar();
//AccountNames = returnValue.ToS tring();
sqlConnection1. Close();
return AccountNames;
} 3 2970
ExecuteScalar is the wrong choice here.
You want
..ExecuteReader
or
LoadDataSet
ExecuteScalar is for 1 single value.
like
Select count(*) as MyCount from dbo.Emp
would be a single value. ExecuteScalar is for that kind of purpose.
"weird0" <am********@gma il.comwrote in message
news:11******** **************@ o5g2000hsb.goog legroups.com...
The given should return A,B that is two rows because both
accountnames A and B have the same user_Id=1 but it is only returning
A when I performed the op. MessageBox.Show ("AccountNames: " +
Object.ToString () );
[WebMethod]
public Object GetAccountNames (string User_Id)
{
//string AccountNames;
Object AccountNames;
// create a Command,Connect ion and Reader object
System.Data.Sql Client.SqlConne ction sqlConnection1 =
new System.Data.Sql Client.SqlConne ction(connectio nString);
System.Data.Sql Client.SqlComma nd cmd = new
System.Data.Sql Client.SqlComma nd();
//Object returnValue;
// Search for the pincode
cmd.CommandText = "SELECT acc_name FROM Account_Informa tion
where user_id='" + User_Id + "'";
cmd.CommandType = CommandType.Tex t;
cmd.Connection = sqlConnection1;
sqlConnection1. Open();
AccountNames = cmd.ExecuteScal ar();
//AccountNames = returnValue.ToS tring();
sqlConnection1. Close();
return AccountNames;
}
I might have misread.
Are you expecting one and only one value?
See here: http://msdn2.microsoft.com/en-us/library/ms978510.aspx
and scroll down to the appendix
Appendix
How to Enable Object Construction for a .NET Class
keep scrolling down a little, basically "every scenario" is listed there.
1 row, multiple columns
1 row, 1 value (what you want)
multi rows, multi columns
"sloan" <sl***@ipass.ne twrote in message
news:eA******** ******@TK2MSFTN GP02.phx.gbl...
ExecuteScalar is the wrong choice here.
You want
.ExecuteReader
or
LoadDataSet
ExecuteScalar is for 1 single value.
like
Select count(*) as MyCount from dbo.Emp
would be a single value. ExecuteScalar is for that kind of purpose.
"weird0" <am********@gma il.comwrote in message
news:11******** **************@ o5g2000hsb.goog legroups.com...
The given should return A,B that is two rows because both
accountnames A and B have the same user_Id=1 but it is only returning
A when I performed the op. MessageBox.Show ("AccountNames: " +
Object.ToString () );
[WebMethod]
public Object GetAccountNames (string User_Id)
{
//string AccountNames;
Object AccountNames;
// create a Command,Connect ion and Reader object
System.Data.Sql Client.SqlConne ction sqlConnection1 =
new System.Data.Sql Client.SqlConne ction(connectio nString);
System.Data.Sql Client.SqlComma nd cmd = new
System.Data.Sql Client.SqlComma nd();
//Object returnValue;
// Search for the pincode
cmd.CommandText = "SELECT acc_name FROM Account_Informa tion
where user_id='" + User_Id + "'";
cmd.CommandType = CommandType.Tex t;
cmd.Connection = sqlConnection1;
sqlConnection1. Open();
AccountNames = cmd.ExecuteScal ar();
//AccountNames = returnValue.ToS tring();
sqlConnection1. Close();
return AccountNames;
}
In addition to what Sloan pointed out, you really want to get into the habit
of using parmeterized queries or even better, stored procedures.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"weird0" wrote:
The given should return A,B that is two rows because both
accountnames A and B have the same user_Id=1 but it is only returning
A when I performed the op. MessageBox.Show ("AccountNames: " +
Object.ToString () );
[WebMethod]
public Object GetAccountNames (string User_Id)
{
//string AccountNames;
Object AccountNames;
// create a Command,Connect ion and Reader object
System.Data.Sql Client.SqlConne ction sqlConnection1 =
new System.Data.Sql Client.SqlConne ction(connectio nString);
System.Data.Sql Client.SqlComma nd cmd = new
System.Data.Sql Client.SqlComma nd();
//Object returnValue;
// Search for the pincode
cmd.CommandText = "SELECT acc_name FROM Account_Informa tion
where user_id='" + User_Id + "'";
cmd.CommandType = CommandType.Tex t;
cmd.Connection = sqlConnection1;
sqlConnection1. Open();
AccountNames = cmd.ExecuteScal ar();
//AccountNames = returnValue.ToS tring();
sqlConnection1. Close();
return AccountNames;
}
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: cs8404 |
last post by:
I cannot quite figure out how to accomplish the following results.
My table is "Products" with the following fields:
ID Item Metal Size Price
1 Ring 18ctGold 4-7 $23.00
67 Ring 18ctGold 8-11 $30.00
70 Ring Silver 4-7 $10.00
75 Ring Silver 8-11 $15.00
|
by: Bruno Panetta |
last post by:
Suppose I have a table Orders with the following fields:
OrderID ProductID OrderDate
I would like a SELECT query to return those rows with multiple values
for both ProductID and OrderDate. For example suppose Orders contains
the following data
OrderID ProductID OrderDate
1 11 12-mar-2005
|
by: Blake |
last post by:
Hello,
I have a database at work that keeps an inventory of cameras by
location. Every week I get a repair estimate sheet that lists cameras
by serial number that need to be repaired. This list is sent to me in
excel. I am trying to make it where I can just copy the column of
serial numbers from the excel list sent to me and paste it directly
into the database to return my information for those cameras. I would
like to do this in a...
|
by: jennk |
last post by:
i am working in Access 97, our database tables are linked from ODBCsqlsvr (not even sure what that means). i have a table where each record has a unique customer and their order information. there are 20 possible items to be ordered.
i need a query that will return a unique row for every item ordered. if the same customer (record) orders 3 items, i need the query to return 3 rows. Each row will have the same customer info (name, address,...
|
by: giloosh |
last post by:
i would like to filter out a bunch rows from a table of sql row
results.
i have a checkbox on each row named checkbox
(x = the current row id)
i will submit the form and take all the rows that are checked and
filter out the ones that are not checked.
so if i had 10 rows and i checked 3 of them then when i submit the
form only those 3 rows will show up.
| |
by: zergziad |
last post by:
Hi All,
I need help on how to return the rows in one particular field as a string with comma separated in
between those data. For example:
Table A
ID Name IsActive
_______________________________________
|
by: raaman rai |
last post by:
Pls see the code below, where i wanted to select all the records from my table where the submdate (submission date) is greater or equal to today's date. Whereas i have two or three records in my table which has this date greater than today but still then i get only one record displayed. I dont find any problem anywhere but still then i dont get the result displayed as i wanted. Pls help me where i have the problem.
<?php
global $database;...
|
by: bilibytes |
last post by:
Hi,
i am having big headaches in trying to find out how to perform a very very simple query.
having a table like this one:
+--------------+----------+---------+
| name | object1 | object2 |
+--------------+----------+---------+
| Mr Brown | 1 | 1 |
|
by: Simon Bernard |
last post by:
Hi there
I am trying to create a database that generates delivery notes. I have an excel spreadsheet linked to the database. From the linked information I need to be able to create a delivery note. But in the table, there are multiple instances of an order number.
Order_No Branch Voucher Code
112 44 5
112 44 10
112 44 20
How can I create a...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |