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

getting the data type conversion error please help me

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 not allowed. Use the CONVERT function to run this query. if any one know something about this then please help me my code is like this:
Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2.         {
  3.  
  4.  
  5.             string employeenominationid;
  6.             employeenominationid=Request.QueryString ["employeenominationid"];
  7.  
  8.  
  9.          SqlConnection oConn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]);
  10.  
  11.             SqlDataAdapter da=new SqlDataAdapter("usp_TestParameters",oConn);
  12.  
  13.             DataSet ds=new DataSet(); 
  14.  
  15.             da.SelectCommand.CommandType=CommandType.StoredProcedure;
  16.  
  17.             da.SelectCommand.Parameters.Add(new SqlParameter("@employeenominationid",employeenominationid));
  18.  
  19.  
  20.  
  21.             SqlParameter datecreated= new SqlParameter("@datecreated", SqlDbType.Int); 
  22.             datecreated.Direction = ParameterDirection.Output; 
  23.             da.SelectCommand.Parameters.Add(datecreated);
  24.  
  25.  
  26.             oConn.Open();
  27.             da.SelectCommand.ExecuteNonQuery();
  28.             oConn.Close();
  29.  
  30.             da.Fill(ds);
  31.  
  32.             this.garidreason.DataSource=ds;
  33.             this.DataBind();
  34.  
  35.             da.Dispose(); 
  36. }
  37.  
  38.  

and my store procedure is like this:

Expand|Select|Wrap|Line Numbers
  1. @employeenominationID int,
  2. @Datecreated datetime OUTPUT
  3. AS
  4. SELECT  datepart(month,@datecreated)  FROM reason WHERE @employeeNominationID = @employeeNominationID
  5. SELECT * FROM reason WHERE EmployeeNominationID = @EmployeeNominationID
  6. RETURN @@ROWCOUNT
  7. select @@RowCount
  8.  
  9. GO
  10.  
  11.  
  12.  
Aug 28 '07 #1
2 3616
nateraaaa
663 Expert 512MB
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 not allowed. Use the CONVERT function to run this query. if any one know something about this then please help me my code is like this:
Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2.         {
  3.  
  4.  
  5.             string employeenominationid;
  6.             employeenominationid=Request.QueryString ["employeenominationid"];
  7.  
  8.  
  9.          SqlConnection oConn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]);
  10.  
  11.             SqlDataAdapter da=new SqlDataAdapter("usp_TestParameters",oConn);
  12.  
  13.             DataSet ds=new DataSet(); 
  14.  
  15.             da.SelectCommand.CommandType=CommandType.StoredProcedure;
  16.  
  17.             da.SelectCommand.Parameters.Add(new SqlParameter("@employeenominationid",employeenominationid));
  18.  
  19.  
  20.  
  21.             SqlParameter datecreated= new SqlParameter("@datecreated", SqlDbType.Int); 
  22.             datecreated.Direction = ParameterDirection.Output; 
  23.             da.SelectCommand.Parameters.Add(datecreated);
  24.  
  25.  
  26.             oConn.Open();
  27.             da.SelectCommand.ExecuteNonQuery();
  28.             oConn.Close();
  29.  
  30.             da.Fill(ds);
  31.  
  32.             this.garidreason.DataSource=ds;
  33.             this.DataBind();
  34.  
  35.             da.Dispose(); 
  36. }
  37.  
  38.  

and my store procedure is like this:

Expand|Select|Wrap|Line Numbers
  1. @employeenominationID int,
  2. @Datecreated datetime OUTPUT
  3. AS
  4. SELECT  datepart(month,@datecreated)  FROM reason WHERE @employeeNominationID = @employeeNominationID
  5. SELECT * FROM reason WHERE EmployeeNominationID = @EmployeeNominationID
  6. RETURN @@ROWCOUNT
  7. select @@RowCount
  8.  
  9. GO
  10.  
  11.  
  12.  
In your stored proc you have Datecreated as a datetime datatype but in your page load event you are passing an int datatype to the stored proc. Change the following line in the page load event to :

Expand|Select|Wrap|Line Numbers
  1. SqlParameter datecreated= new SqlParameter("@datecreated", SqlDbType.DateTime); 
Now your error should be resolved.

Nathan
Aug 28 '07 #2
thanks very much for help me .my problem is solved now
Aug 28 '07 #3

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

Similar topics

9
by: Ksenia Marasanova | last post by:
Hi, I have a little problem with encoding. Was hoping maybe anyone can help me to solve it. There is some amount of data in a database (PG) that must be inserted into Excel sheet and emailed....
3
by: David McManus | last post by:
I am trying to use a query to filter SQL Server 2000 records by a date value. Here is relevant columns in my database table (tblContent): title starting .... and here is my query: Query...
1
by: Luis Esteban Valencia | last post by:
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source...
4
by: Gary | last post by:
Hi, I have a temperature conversion program down pat, but I was told to add an average, meaning, i need to get the average temperature for as many times as it was entered. i do not know where to...
12
by: Angus | last post by:
I am writing a class as a wrapper around a std::map. The class is: template<class TKey, class TValue> class CGeneralMap : protected map<TKey, TValue> At the moment I have basic functions like...
2
by: Manikandan | last post by:
Hi, I have a program written in .Net Framework 1.1 using Visual studio enterprise edition 2003. I tried compiling the same program in visual c# express edition 2005. I'm getting following...
6
by: Rahul | last post by:
Hi Everyone, I have the following code, class B; class A { public : operator B();
4
by: jehugaleahsa | last post by:
Hello: Say I were to query the schema tables from a database management system. Say I got a DataType field that held the string 'VARCHAR2'. Now, I know that VARCHAR2 associates to System.String....
7
vikas251074
by: vikas251074 | last post by:
I am getting error above in following code since few days giving tension day and night. How can I solve this? I am facing since Oct.25. in line no. 362 After doing a lot of homework, I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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...

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.