473,413 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

SQL Syntax in Select Statement of a SQlDataAdapter

Hi!

I have a SQLDataAdapter and I want to retrieve data from my database in SQL Server 2005 . Supposing I have two tables named Guest, Sales and one of the columns is GuestFirstName. I want to retrieve One record(GuestFirstName) from table Guest that has the same GuestID as in Sales GuestID. Also in the Sales table the column SalesStatus needs to contain the text 'ToGuestInvoice'.

Directly in SQL Server 2005 I can perform this query with the following syntax:
Expand|Select|Wrap|Line Numbers
  1. SELECT g.GuestFirstName as GuestFirstName
  2. From Guest AS g, Sales As s 
  3. WHERE g.GuestID = s.GuestID AND s.SalesStatus = 'ToGuestInvoice' 
  4. GROUP BY g.GuestFirstName 
  5.  
But when I write this query as a select query in my SqlDataAdapter I want to express GuestFirstName as a parameter and use that parameter in run time but the syntax seems to be different because the query retrieves no records from the database. (I tried to express the parameter as @GuestFirstName but that does not work)
How can that be done?

I wrote this code: (Visual Studio 2005-C#)

Expand|Select|Wrap|Line Numbers
  1.            string sqlq = @" Select g.GuestFirstName from Guest g, Sales s where g.GuestID = s.GuestID And s.SalesStatus Like 'ToGuestInvoice%' GROUP BY g.GuestFirstName ";
  2. SqlDataAdapter da = new SqlDataAdapter(sqlq, dbConnection);
  3.  
  4. myCommand.CommandText = sqlq;
  5. myCommand.Parameters.Add("@GuestFirstName",SqlDbType.VarChar).Value = da;
  6.  
Jan 3 '08 #1
2 2322
Can Anyone assist me? I'd really appreciate it!

George
Jan 4 '08 #2
Anxiously waiting for a reply! Has anyone encountered this problem or something similar?? I would like to know urgently....i'll be grateful for any help possible...
Jan 4 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John Hall | last post by:
We need to read a SQL database containing a mix of English words and Chinese Characters. We think we need to use the N'xxxx' to read the Unicode. We have one place where the SELECT statement...
5
by: ST | last post by:
Hi, I'm sort of in a rush here...I'm sort of new to vb.net and I'm trying to write the syntax to check a sql table to see if the record already exists based on firstname and lastname text fields...
3
by: Assimalyst | last post by:
Hi, I'm getting the above error when i try to fill a Dataset through a dataAdapter. I presume it is to do with the sql statement. Below is the relevant code: string strPntUnitID =...
2
by: jez123456 | last post by:
Hi. I have a web form with a datagrid that displays employees who are on holiday. One of the datagrid columns shows the date of their last day of holiday, but what I really require is the Start Back...
7
by: Matt Jensen | last post by:
Howdy Fairly simple question I think, I presume the answer is no it can't be reused for 2 *SELECT* statements, but just hoping for clarification. Just asking in the interests of trying to minimise...
1
by: LIN | last post by:
Hi, I have dataset which contains the data like this TranDate PurchaseVal ------------ ------------- 2003-01-01 51 2003-01-02 52 2003-01-03 ...
1
by: Agnes | last post by:
Mycode shown as the following:- it is very simple code. However, I got an error on "daExBL.Fill(dsExBL) " Is there problem onmy syntax or on my SQL server ? Dim conSea As New...
12
by: Brad Baker | last post by:
I am trying to write a simple ASP.net/C# page which allows users to select some values and produce a report based on a SQL query. I have a self posting dropdown form which allows users to select...
18
by: rcoco | last post by:
Hi all, I have a datagrid with Button column select in form of hyperlink. On the same page, I have another datagrid that insert data and one column(Name) has Names of a user that is inserting...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.