Click here to Skip to main content
15,920,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m working on dot net mvc.i am creating webservices. it is showing me error like this:
System.Data.SqlClient.SqlException: Error converting data type varchar to numeric.

while inserting data in to table

What I have tried:

my stored procedure is:
CREATE Proc [dbo].[Usp_EmployeeCheckLocation_Insert]            
@DeviceId nvarchar(50),            
@EmployeeCode nvarchar(50),            
@CallId nvarchar(50),            
@Latitude decimal(18,10),            
@Longitude decimal(18,10),            
@Status nvarchar(50),            
@Checkdate datetime,            
@Source nvarchar(25),    
@OtherVisitStatus nvarchar(50)          
AS            
IF @Status='CheckIn'            
BEGIN            
  INSERT INTO  EmployeeCheckLocation            
   (DeviceId,            
   EmployeeCode,            
   CallId,            
   Latitude,            
   Longitude,            
   Status,            
   CreatedOnUtc,            
   Source,    
     OtherVisitStatus)            
   values            
   (@DeviceId,            
   @EmployeeCode,            
   @CallId,            
   @Latitude,            
   @Longitude,            
   @Status,            
   @Checkdate,            
   @Source,    
   @OtherVisitStatus )            
END            



and my web services method is:
   [WebMethod]
        public string EmployeeAttendanceLocation(string lati, string longi, string status, string checkDate, string deviceId, string callId, string empCode, string Source, string ProjectName, string OtherVisitStatus)
        {
            SqlConnection myConnection = new SqlConnection();
            var conString = System.Configuration.
                 ConfigurationManager.ConnectionStrings["Server"];
            string strConnString = conString.ConnectionString;
            myConnection.ConnectionString = strConnString;
            myConnection.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = myConnection;
            cmd.CommandType = CommandType.StoredProcedure;
            string msg = null;
            //  DateTime date = DateTime.UtcNow;
            //  date = DateTime.Parse(checkDate);
            cmd.CommandText = "Usp_EmployeeCheckLocation_Insert";
         
           

                cmd.Parameters.AddWithValue("@DeviceId", deviceId.ToString());
                cmd.Parameters.AddWithValue("@EmployeeCode", empCode.ToString());
                cmd.Parameters.AddWithValue("@CallId",callId.ToString());
                cmd.Parameters.AddWithValue("@Latitude", lati.ToString());
                cmd.Parameters.AddWithValue("@Longitude", longi.ToString());
                cmd.Parameters.AddWithValue("@Status", status.ToString());
                cmd.Parameters.AddWithValue("@Checkdate", checkDate.ToString());
                cmd.Parameters.AddWithValue("@Source", Source.ToString());
                cmd.Parameters.AddWithValue("@OtherVisitStatus",SqlDbType.NVarChar).Value=DBNull.Value;
              

          
            int j = cmd.ExecuteNonQuery();
      
            if (j > 0)
            {

                msg = "success";
            }
            else
            {
                msg = "fail";
            }
            cmd.Connection.Close();
return msg;

}
Posted
Updated 14-Mar-17 19:43pm
Comments
Karthik_Mahalingam 15-Mar-17 1:14am    
check the lati and longi value, it should be in a valid number format.
Member 12300036 15-Mar-17 1:39am    
when i put callid=4776060423-471 like this...then only show error..
its not lati long problem
Karthik_Mahalingam 15-Mar-17 1:40am    
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.
Member 12300036 15-Mar-17 1:41am    
ok
Karthik_Mahalingam 15-Mar-17 1:41am    
what is CallId datatype in sql table ?

1 solution

Hi,

use the sqldbtype at every parameter like u did at last parameter
 
Share this answer
 
Comments
Member 12300036 15-Mar-17 2:00am    
still not working

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



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