473,394 Members | 1,761 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,394 software developers and data experts.

Implicit conversion from data type datetime to int

12
Hi, I'm trying to retrieve some information from my database, but somehow i get this error:

Behind code:
Expand|Select|Wrap|Line Numbers
  1. public void binddata()
  2.     {
  3.         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  4.               DataSet ds = new DataSet();
  5.  
  6.         SqlDataAdapter da = new SqlDataAdapter("getRoomNEquip2", con);
  7.         da.SelectCommand.CommandType = CommandType.StoredProcedure;
  8.          da.SelectCommand.Parameters.Add("@Location", SqlDbType.VarChar, 50);
  9.  
  10.         da.SelectCommand.Parameters["@Location"].Value = DropDownLocation.SelectedItem.Text;
  11.  
  12.  
  13.         da.Fill(ds);
  14.  
  15.         ds.Relations.Add("myRelation",
  16.             ds.Tables[0].Columns["ID"],
  17.             ds.Tables[1].Columns["ID"]);
  18.  
  19.         MeetRoomList.DataSource = ds.Tables[0];
  20.         MeetRoomList.DataBind();
  21.  
  22.     }
this is my stored procedure:
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [dbo].[Getroomnequip2] 
  2.     @Location VARCHAR(50)
  3. AS 
  4.  
  5.   BEGIN 
  6.       CREATE TABLE #temp 
  7.         ( 
  8.            name          VARCHAR(50), 
  9.            id            INT, 
  10.            location      VARCHAR(50), 
  11.            fk_type       VARCHAR(10), 
  12.            fk_equipments INT, 
  13.            TYPE          VARCHAR(10), 
  14.            fk_meetroom   INT, 
  15.            status        CHAR(1), 
  16.            note          TEXT, 
  17.            DATE             DATETIME,
  18.            fk_user       INT, 
  19.            reg_date      DATETIME, 
  20.         ) 
  21.  
  22.       INSERT INTO #temp 
  23.       SELECT roomndato.mrn     AS name, 
  24.              a.id, 
  25.              a.location, 
  26.              a.fk_type, 
  27.              b.fk_equipments, 
  28.              b.TYPE, 
  29.              c.fk_meetroom, 
  30.              c.status, 
  31.              c.note, 
  32.              c.fk_user, 
  33.              c.reg_date, 
  34.              roomndato.maxdate AS DATE 
  35.       FROM   (meetroom AS a 
  36.               FULL JOIN meetroomtypes AS b 
  37.                 ON a.fk_type = b.TYPE 
  38.               FULL JOIN equipmentstatus AS c 
  39.                 ON b.fk_equipments = c.fk_equipments 
  40.                    AND a.id = c.fk_meetroom) 
  41.              LEFT JOIN (SELECT DISTINCT a.name      AS mrn, 
  42.                                         MAX(c.DATE) AS maxdate 
  43.                         FROM   (meetroom AS a 
  44.                                 FULL JOIN meetroomtypes AS b 
  45.                                   ON a.fk_type = b.TYPE 
  46.                                 FULL JOIN equipmentstatus AS c 
  47.                                   ON b.fk_equipments = c.fk_equipments 
  48.                                      AND a.id = c.fk_meetroom ) 
  49.                         GROUP  BY a.name) AS roomndato 
  50.                ON a.name = roomndato.mrn 
  51.                   AND c.DATE = roomndato.maxdate 
  52.       WHERE  location = @Location 
  53.       ORDER  BY name, 
  54.                 DATE DESC 
  55.  
  56.       SELECT DISTINCT name, 
  57.                       id, 
  58.                       TYPE 
  59.       FROM   #temp 
  60.  
  61.       SELECT * 
  62.       FROM   #temp 
  63.   END 
  64.  
  65. DROP TABLE #temp  
I really dont understand why i get the error, hope somebody can help me please
Apr 24 '10 #1
4 2468
tlhintoq
3,525 Expert 2GB
The error message pretty much says it all
error: Implicit conversion from data type datetime to int
Someplace you have an int and you are trying to implicitly convert it to a datetime and the OS doesn't know how to do that.

If you are storing a date as an int in your database you will need to expressly tell your program how to convert it back to a datetime object.
Apr 24 '10 #2
7effrey
12
i know what it means, but the thing is im not trying to convert anything. im just trying to read some data from the database. All my date fields are of the type datetime, and i dont understand why it says im trying to load it as an int.. how can i find out where the problem is?

I think the problem is in my stored procedure
Apr 24 '10 #3
7effrey
12
I found the error. Apparently you must name the table content in the same order as you select them

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE #temp 
  2.         ( 
  3.              name varchar(50),
  4.              id , 
  5.              location varchar(50), 
  6.              fk_type varchar(10), 
  7.              fk_equipments int, 
  8.              TYPE varchar(10), 
  9.              fk_meetroom int, 
  10.              status char(1), 
  11.              note text, 
  12.              fk_user int, 
  13.              reg_date DateTime,
  14.              date DateTime, 
  15.         ) 
  16.  
  17.       INSERT INTO #temp
  18.       SELECT roomndato.mrn     AS name, 
  19.              a.id, 
  20.              a.location, 
  21.              a.fk_type, 
  22.              b.fk_equipments, 
  23.              b.TYPE, 
  24.              c.fk_meetroom, 
  25.              c.status, 
  26.              c.note, 
  27.              c.fk_user, 
  28.              c.reg_date, 
Apr 25 '10 #4
Frinavale
9,735 Expert Mod 8TB
Hmm I would have said that to fix this problem you should use Explicit Casting when reading the values retrieved from the database. If you are expecting an Int, then specify that using explicit casting.

-Frinny
Apr 27 '10 #5

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

Similar topics

2
by: Russell Reagan | last post by:
In a newer version of a chess program I am writing, I have created classes that are (more or less) drop in replacements for things that used to be plain old integer or enumerated variables (colors,...
1
by: Christophe Poucet | last post by:
Hellom I have an issue with implicit conversions. Apparently when one calls an operator on a class Y which has a conversion operator to class X which has the operator . Sadly it will not do...
15
by: buda | last post by:
Let me see if I got this :) 1. I know the rules for type conversions in arithmetic expressions 2. I know that an implicit type conversion is done at assignment, so float x = 1.23; int t = (int)...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
11
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
36
by: Chad Z. Hower aka Kudzu | last post by:
I have an implicit conversion set up in an assembly from a Stream to something else. In C#, it works. In VB it does not. Does VB support implicit conversions? And if so any idea why it would work...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
2
by: preeti13 | last post by:
i am tring to retrive the value form the data base but getting erorr i tried so many way but i didn't get the value i got the erorr like this: Implicit conversion from data type datetime to int is...
5
by: =?Utf-8?B?Q2hyaXMgRA==?= | last post by:
Hi - I was hoping to use the range validator to check that the user's age is between 10 & 65 based upon an entered DOB. I thought I could use max&min date variables in the Validator & have those...
1
Manikgisl
by: Manikgisl | last post by:
But the problem is we have dates in Varchar instead Datetime While Converting Varchar To Datetime All four formats are unable to Convert ie select Convert(Datetime,'18-11-2008 2:35:19...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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...

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.