|
Hi,
I was wondering if I could reduce my SQL statements when using comboboxes for search parameters.
For example:
Combobox with this list:
<Categories
Shirts
Pants
Shoes
Because I don't want a Category search if "<Categories" is selected I have an if statement like this:
if (comboBox_Categories.SelectedIndex != 0)
{
SELECT yada yada WHERE ItemID=8 AND Categories=comboBox_Categories.SelectedValue
}
else
{
SELECT yada yada WHERE ItemID=8
}
I have several ComboBoxes that supply possible parameter variables (that may or may not be used). This creates many possible SQL statements. Any sugestions on how to go about this differently?
Thanks!
Ron
-- modified at 18:37 Sunday 13th August, 2006
|
|
|
|
|
SELECT ColumnNames
FROM TableName
WHERE ItemId = @ItemId AND
(@CategoryID IS NULL OR CategoryID = @CategoryID)
The last line is the key - If you send an empty selection on the ComboBox as a DBNull.Value to the SqlCommand then you'll get the behaviour you want out of one SQL Command.
The last line basically means. If the @CategoryId is NULL then I'm not interested in anything else, I'm TRUE therefor the whole OR expression will be TRUE . If the @CategoryID is something other than NULL then I have to evaluate that against the column CategoryID
Does this help?
|
|
|
|
|
Thanks Colin!
I thought there might be a better way to go about it.
I guess it's kinda like an "else if" statement... it'll only
go the the "else if" if the "if" statement was not satisfied.
Thanks again Colin,
Ron
|
|
|
|
|
hi.
i want to know how i can handle closing page event.
i mean that if i want to do something before closing page.
thank for help.
ABONASSER
|
|
|
|
|
This forum deals with database issues. Perhaps you might want to try a forum that deals with web application issues.
|
|
|
|
|
Hey.
I know that the Structured Query Language for MDB (Access) is differrent then the SQL of MySQL.
I'm currently moving my databases from Access to MySQL, but I don't know the syntax of the SQL.
If anyone can help me, or give me a dictionary or some internet help and some samples, I would appriciate it.
Thanks alot.
NaNg.
|
|
|
|
|
See my answer to you in the C# forum.
|
|
|
|
|
What is the erorr with this select statement
Set RS = DB.OpenRecordset("select * from Users where User_name=" & Text1.Text & " and User_pass=" & Text2.Text & " and User_type=" & Combo1.List(Combo1.ListIndex))
I use it in vb6 with DAO 3.5
but the compiler tell that too few parameter.Expected 2
all these fields in the table is text
please help
thanx
BE OR NOT TO BE
|
|
|
|
|
You are missin single quotes around the sring values (Text1.Text, Text2.Text) so they are treated as symbolic names for parameters: (extra spaces around ' not needed)
"select * from Users where User_name= ' " & Text1.Text & " ' and User_pass= ' " & Text2.Text & " ' and
|
|
|
|
|
Hello !
Can anybody help me ?
I'm interested to develop an application that uses MySql.Data.dll at runtime with reflection. I got a NullReferenceException when I try to set the value of SelectCommand in MySql.Data.MySqlClient.MySqlDataAdapter namespace.
I don't understand why, I've used Activator.CreateInstance....
Here It is the code of my app:
Dim asm As Assembly = Assembly.LoadFrom("C:\MySql.Data.dll")
Dim myConnectionString As String
myConnectionString = "server=localhost;" _
& "uid=root;" _
& "pwd=xxxxxxx;" _
& "database=test;"
Dim params() As Object = {myConnectionString}
Dim MySqlConnectionClass As Object = Activator.CreateInstance(asm.GetType("MySql.Data.MySqlClient.MySqlConnection"), params)
Dim t As Type = MySqlConnectionClass.GetType
Dim MySqlDataAdapterClass As Object = Activator.CreateInstance(asm.GetType("MySql.Data.MySqlClient.MySqlDataAdapter"))
Dim t2 As Type = MySqlDataAdapterClass.GetType
Dim params2() As Object = {"SELECT * FROM WEB_USER WHERE UserName= 'test' AND Password = 'test'", MySqlConnectionClass}
Dim MySqlCommandClass As Object = Activator.CreateInstance(asm.GetType("MySql.Data.MySqlClient.MySqlCommand"), params2)
Dim t3 As Type = MySqlCommandClass.GetType
Dim mi As PropertyInfo = t2.GetProperty("SelectCommand", BindingFlags.Public)
mi.SetValue(MySqlDataAdapterClass, t3, Nothing) <-- ERROR
I've also tried (in substitution to the last line):
Dim mi As PropertyInfo = t2.GetProperty("SelectCommand", BindingFlags.Public)
mi.SetValue(MySqlDataAdapterClass, MySqlConnectionClass, Nothing) <-- ERROR
Many Thanks !
Gian Paolo
|
|
|
|
|
Well, neither of the two lines you tried would appear to do what you want.
Gian Paolo WNA wrote: mi.SetValue(MySqlDataAdapterClass, t3, Nothing)
This attempts to make a call that would look like this normally:
MySqlDataAdapterClass.SelectCommand = t3 t3 is a Type object, but the property is looking for a MySqlCommand object.
Gian Paolo WNA wrote: mi.SetValue(MySqlDataAdapterClass, MySqlConnectionClass, Nothing) <-- ERROR
That attempt would look like this normally:
MySqlDataAdapterClass.SelectCommand = MySqlConnectionClass Again, this is the wrong object type. The SelectCommand property is looking for a MySqlCommand object, but you supplied a MySqlConnection object.
You might wish to try this:
mi.SetValue(MySqlDataAdapterClass, MySqlCommandClass, Nothing)
|
|
|
|
|
Hey guys, Could someone give me a list of all the SQL Server 200 updates? I just want the names of each and every ittby bitty one and not the download links! Thanks in advance.
|
|
|
|
|
|
For publicly available releases, all you really need is SQL Server 2000 Service Pack 4. There have been no security patches since then. If you want to search for security bulletins for a specific product, try here[^].
Future updates for SQL Server 2000 will be available on Microsoft Update. Go to http://update.microsoft.com/microsoftupdate/[^] to get started. If you have Windows Server Update Services, updates for SQL Server 2000 will be on there.
If you're experiencing a specific problem, contact Support.
|
|
|
|
|
Can I add or remove column in datagrid at runtime
neeraj
|
|
|
|
|
Hi everybody
I am a beginner and facing the problem in calling a Stored Procedure from within my VB.NET 2005, as below:
MY Stored Procedure goes like;
ALTER PROCEDURE ByRoyalty @percentage int, @avgprice float Output<br />
AS<br />
SELECT @avgprice= AVG(price) FROM titles<br />
SELECT au_id FROM titleauthor<br />
WHERE titleauthor.royaltyper = @percentage<br />
DECLARE @numtitles Int<br />
SELECT @numtitles=COUNT(*) FROM titles<br />
RETURN @numtitles
My VB code is as below:
Dim cmd As New SqlCommand("ByRoyalty", Conxn)<br />
With cmd<br />
.CommandType = CommandType.StoredProcedure<br />
<br />
.Parameters.Add("@numtitles", SqlDbType.Int)<br />
.Parameters(0).Direction = ParameterDirection.ReturnValue<br />
<br />
.Parameters.AddWithValue("@percentage", 100)<br />
.Parameters(1).Direction = ParameterDirection.Input<br />
<br />
.Parameters.Add("@avgprice", SqlDbType.Float)<br />
.Parameters(2).Direction = ParameterDirection.Output<br />
End With<br />
Dim dr As SqlDataReader = cmd.ExecuteReader()
Running the above vb code reports the following error:
"Procedure or function ByRoyalty has too many arguments specified."
Please help
-- modified at 8:06 Friday 11th August, 2006
|
|
|
|
|
numtitles needs to be an input to the procedure:
Try:
<br />
ALTER PROCEDURE ByRoyalty @percentage int, @avgprice float Output, @numtitles int Output<br />
AS<br />
SELECT @avgprice= AVG(price) FROM titles<br />
SELECT au_id FROM titleauthor<br />
WHERE titleauthor.royaltyper = @percentage<br />
SELECT @numtitles=COUNT(*) FROM titles<br />
RETURN @numtitles<br />
Mike Lasseter
|
|
|
|
|
Sorry, it still reports the same error. Any other idea, please!
|
|
|
|
|
Hi Friend,
Can you change the line as follows.
.Parameters.Add("@percentage", 100)
- I think 'Add' Method is enough here.
With Regards,
Pandian S
|
|
|
|
|
THOUSANDS OF PARDONS to all the friends who tried to help. The problem was something different.
As a matter of fact, all the changes I was making had been commencing in the LOCAL COPY of my database. For this reason, my changes did not reflect in the result set.
I again aplogize everybody.
With gread regards.
|
|
|
|
|
sqlmanager.exe - Application Error
The instruction at "0x780104ac" referenced memory at "0x009e00af".The memory could not be "read".
|
|
|
|
|
You're best reporting that to Microsoft.
|
|
|
|
|
hi there,
I've got a table with
ID int [primary key]
TypeID int
PATH varchar(25)
now I'd like to do something like "select the ID of a random record with TYPEID = 1".
is this possible in TSQL? If so, can somebody drop a hint?
thanks in advance!
/matthias
I love deadlines. I like the whooshing sound they make as they fly by. [Douglas Adams]
|
|
|
|
|
|
Is school back already ??? Oh well there goes summer.
Look where you want to go not where you don't want to crash.
Bikers Bible
|
|
|
|