Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I've written a program to send out an email when currentstock goes below minimumrequired.

Here's part of my code:

VB
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
 
con.ConnectionString = "Data Source=######;Initial Catalog=######;Integrated Security=True"
        con.Open()
        cmd.Connection = con
        cmd.CommandText = "SELECT * FROM [" + dbase + "] WHERE CurrentStock < MinimumRequired"


It displays all the ones that the current stock is below the minimum, but one or two other parts are being displayed aswell. E.G. its displaying stock of 10 and the minimum is 2, so it shouldnt be displaying.

Have i missed something out of the code above?


Cheers for any help,
Pete
Posted
Comments
Mukesh Ghosh 31-Jul-13 5:43am    
What is the datatype for CurrentStock & MinimumRequired?
PeterHall 31-Jul-13 6:17am    
varchar(MAX),

Cheers

1 solution

I think issue is with datatype of CurrentStock & MinimumRequired.
check for datatype.

for eg.
below case will say 2 is greater then 10

SQL
declare @a varchar(10)
declare @b varchar(10)

set @a='10'
set @b='2'

select case when @a >@b then @a +' is greater' when @a = @b then 'Both are equal'
else @b +' is greater' end as Greater




output:

Greater
2 is greater
 
Share this answer
 
v2
Comments
PeterHall 31-Jul-13 6:16am    
ah right, just checked now my datatype in the sql table is varchar(MAX) for both current stock and minimum required, what would I need to set that to?

Thanks
Adarsh chauhan 31-Jul-13 6:17am    
if your stock is in no. of pieces then you can set it to int else decimal.
I would suggest you to go for decimal as stock can be in length, weight or no. of pieces etc. so int would work right for no. of pieces only..
PeterHall 31-Jul-13 6:22am    
I tried both int and decimal, it seemed to throw an exception "Conversion from string "Stock Control " to type 'Double' is not valid.

Any ideas?
Adarsh chauhan 31-Jul-13 6:25am    
have you changed datatype in your database??
when this error is coming???
PeterHall 31-Jul-13 6:28am    
On the dropdown box i selected "decimal(18, 0)" in visual studio.

Heres the exception it threw:

System.InvalidCastException: Conversion from string "Conformal Coating Stock Control " to type 'Double' is not valid. ---> System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat)
--- End of inner exception stack trace ---

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900