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;
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;
}