Problems with Select statement! | Member | | Join Date: Nov 2007 Location: Belize City, Belize
Posts: 97
| |
Is this a proper statement to make if I want to select from Two tables called Guest and Sales so that i can pass those parameters into some labels? For example, I want GuestFirstName to be @GuestFirstName and display in a label. -
string sSQL = " SELECT GuestFirstName,GuestLastName,GuestAddress,Country,GuestPhone,GuestEmail,GuestArrivedDate,SaleTotal,InvoiceNumber,SaleItem,SaleType,SaleDiscount,Date,Quantity,SalePrice FROM Guest, Sales WHERE GuestFirstName,GuestLastName,GuestAddress,Country,GuestPhone,GuestEmail,GuestArrivedDate,SaleTotal,InvoiceNumber,SaleItem,SaleType,SaleDiscount,Date,Quantity,SalePrice = @GuestFirstName,@GuestLastName,@GuestAddress,@Country,@GuestPhone,@GuestEmail,@GuestArrivedDate,@SaleTotal,@InvoiceNumber,@SaleItem,@SaleType,@SaleDiscount,@Date,@Quantity,@SalePrice ";
-
-
Thanks in advance,
George
|  | Expert | | Join Date: Mar 2007 Location: England
Posts: 1,083
| | | re: Problems with Select statement!
The query looks wrong, and I don't know what this means. Quote:
For example, I want GuestFirstName to be @GuestFirstName and display in a label.
Are you trying to use SQL variables?
May I suggest you write a shorter test query first, get that working then expand it to SELECT the fields required.
| | Member | | Join Date: Nov 2007 Location: Belize City, Belize
Posts: 97
| | | re: Problems with Select statement! Quote:
Originally Posted by code green The query looks wrong, and I don't know what this means.
Are you trying to use SQL variables?
May I suggest you write a shorter test query first, get that working then expand it to SELECT the fields required. Ok, the thing is I'm not quite sure about the syntax -
string sSQL = " SELECT GuestFirstName FROM Guest WHERE GuestFirstName = @GuestFirstName ";
-
The Select I know it can't be right because it somehow seems redundant, I want the value i get from the table (In this case: GuestFirstName) be passed into a parameter so i can manipulate it to display on either a textbox, label or comboBox. I have created a class that allows me to have a dataview, therefore i need that parameter to permit the view. I just need to know the functional syntax as to how to change a value so I can use it.
e.g. -
myCommand.Parameters.Add("@GuestFirstName", SqlDbType.VarChar).Value = label.Text;
-
Later on I will use this using the class this way:
[code]
label.DataBindings.Clear();
label.DataBindings.Add("Text", mydbview, "Guest.GuestFirstName");
(public string) GuestID = label.Text;
[\CODE]
I hope this is clear...
|  | Expert | | Join Date: Mar 2007 Location: England
Posts: 1,083
| | | re: Problems with Select statement!
The below syntax is correct, assuming you want to use a user-defined variable @GuestFirstName - string sSQL = " SELECT GuestFirstName FROM Guest WHERE GuestFirstName = @GuestFirstName ";
I can't see where you are defining or reading the value of @GuestFirstName,
but this query will return a GuestFirstName from the table Guest that has the value inside @GuestFirstName.
Don't know why you want that. I see what you mean about redundant.
But to clarify, the query RETURNS a value from the table.
Not change a value.
If you want to read the returned value into a SQL variable you need - string sSQL = " SELECT @GuestFirstName := GuestFirstName FROM Guest WHERE GuestFirstName = 'a value such as id ";
My VB is a little rusty so I hope this is what you are trying to do
| | Member | | Join Date: Nov 2007 Location: Belize City, Belize
Posts: 97
| | | re: Problems with Select statement! Quote:
Originally Posted by code green The below syntax is correct, assuming you want to use a user-defined variable @GuestFirstName - string sSQL = " SELECT GuestFirstName FROM Guest WHERE GuestFirstName = @GuestFirstName ";
I can't see where you are defining or reading the value of @GuestFirstName,
but this query will return a GuestFirstName from the table Guest that has the value inside @GuestFirstName.
Don't know why you want that. I see what you mean about redundant.
But to clarify, the query RETURNS a value from the table.
Not change a value.
If you want to read the returned value into a SQL variable you need - string sSQL = " SELECT @GuestFirstName := GuestFirstName FROM Guest WHERE GuestFirstName = 'a value such as id ";
My VB is a little rusty so I hope this is what you are trying to do Yeah I see what you mean when you say u cant see where i'm reading the value, the reason is because I'm using it later on to be displayed in an excel cell. And well I only need to return a value from the table since I'm just using it for a person to view it. Appreciate it.
Sincerely,
George
|  | Similar MySQL Database bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|