473,408 Members | 2,087 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,408 software developers and data experts.

Code error : Cannot implicitly convert type

Expand|Select|Wrap|Line Numbers
  1. public void Update_Stock(Inseed Is)
  2.         {
  3.             if (con.State == ConnectionState.Open)
  4.             {
  5.                 con.Close();
  6.             }
  7.  
  8.             try
  9.             {
  10.                 string str = "Select CurrStock from StockInMaster where Name = '" + Is.ProductName+ "'";
  11.                 Int64 Units = 0;
  12.  
  13.                 SqlCommand cmd = new SqlCommand(str, con);
  14.                 con.ConnectionString = cnstr;
  15.                 con.Open();
  16.  
  17.                 SqlDataReader dr = cmd.ExecuteReader();
  18.  
  19.                 while (dr.Read())
  20.                 {
  21.                     if (dr["CurrStock"].ToString() == "0")
  22.                     {
  23.                         Units = 0;
  24.                     }
  25.                     else
  26.                     {
  27.                         Units = Convert.ToInt64(dr[0]) - Is.Quantity; // Error is in this line(Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)    
  28.                     }
  29.                 }
  30.  
  31.  
  32.                 string str1 = "Update StockInMaster set CurrStock = " + Units +
  33.                        " where Name = '" + Is.ProductName + "'";
  34.  
  35.  
  36.  
  37.                 SqlCommand cmd1 = new SqlCommand(str1,con);
  38.                 cmd1.ExecuteNonQuery();
  39.                 cmd1.Dispose();
  40.                 con.Close();
  41.             }
  42.             catch (Exception ex)
  43.             {
  44.                 throw new Exception(ex.Message.ToString());
  45.             }
  46.         }
  47.  
Thanks in advance
Jul 25 '10 #1
3 3006
iohos
45
chk d data sequencing step 37- step 40.......
Jul 25 '10 #2
GaryTexmo
1,501 Expert 1GB
What data type is Is.Quantity? Is it a double? If so, I believe when you do a math operation between a double and an int, the result automatically becomes a double.

As the line suggests, you need a cast on that line to make the result an integer. You can either cast Is.Quantity to an integer, or you can cast the final result to an integer... or in your case, Int64 :)
Jul 25 '10 #3
ThatThatGuy
449 Expert 256MB
@sappyjosh
Can you post the class Inseed it seems that the Is.Quantity is making the problem
Jul 26 '10 #4

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

Similar topics

0
by: Terminal882003 | last post by:
Hi, Here I have a question about MSCommLib. I need to dynamically add activeX controls that requires run-time license for MSCommLib. The following is the actual code: AxMSCommLib.AxMSComm...
3
by: Anita C | last post by:
I have the foll. code to update the value of an attribute: xmlDocument.Load("abc.xml"); XmlAttribute xmlAttrib = xmlDocument.SelectSingleNode(root/web/theme/@desc); xmlAttrib.Value =...
22
by: Christoph Boget | last post by:
I am getting an error (a few among many) for the following lines of code: retval.BrokerName = (( curRow == System.DBNull.Value ) ? SqlString.Null : (string)curRow ); retval.BrokerGroupId = ((...
6
by: juli | last post by:
I declared: public delegate void PaintEventHandler(object objSender,PaintEventArgs pea); and this.Paint+=new PaintEventHandler(MyPaintHandler); and the: static void MyPaintHandler(object...
2
by: Jeff | last post by:
I get the following error: Cannot implicitly convert type 'Factory.Stack.pArrayStack' to 'Factory.Stack.StackDefs.ImStack' at compile time. I thought perhaps there was a mismatch between the...
2
by: Patrick Olurotimi Ige | last post by:
When i convert:- this code from VB to C# Why do i get error "Cannot implicitly convert type 'object' to 'bool' VB --- If cmdcommand.Parameters("ReturnValue").Value = 1 Then lblStatus.Text =...
9
by: Andy Sutorius | last post by:
Hi, I am receiving the error when compiling the project, "cannot implicitly convert type object to string". The error points to this line of code and underlines the dtrRecipient:...
3
by: Patrick Olurotimi Ige | last post by:
compiling the code below i get the error:- Cannot implicitly convert type 'object'to 'System.Xml.XmlDocument' I'm getting the error on this line:- myXml.Document =...
1
by: alex21 | last post by:
Ok i am trying to use a Linq query to access a dictionary. public static Dictionary<string, Client> Clients = new Dictionary<string, Client>();Using this Linq query: IEnumerable<Staff> loginquery...
4
by: clflyer | last post by:
I have a small problem. I'm pretty much a newbie to C# coming out of VB.Net. I have a windows form that has a GroupBox named grpSoldTo. I want to be able to clear all the textboxes and comboxes...
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
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...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.