我使用C#創建一個Web應用程序,將數據類型varchar轉換爲float時出錯。 C#web服務
這裏是我的,保存記錄
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public void saverecd(string id, string particular,string amt,string adjamt,string tdate, string total, string date, string utrno, string modeofpayment, string transferdate,string trainer, string typeofadj, string bnkid)
{
List<string> td = tdate.Split(',').ToList();
int i = 0;
foreach (string t in td)
{
SqlCommand cmd = new SqlCommand("insert into finalinstructoreexpense(sonvinid,particulars,amount,totalamt,date,utno,paymentid,paymode,issuedate,sondate,trainer,type,bank_id) values('@sonvinid','@particulars','@amount','@totalamt','@date','@utno','@paymentid','@paymode','@issuedate','@sondate','@trainer','@type','@bank_id')", con);
con.Open();
cmd.Parameters.Add("@id", SqlDbType.Int).Value =Convert.ToInt32(id);
cmd.Parameters.Add("@particular", SqlDbType.NVarChar).Value = particular;
cmd.Parameters.Add("@amount",SqlDbType.Float).Value=adjamt.Split(',')[i];
cmd.Parameters.Add("@totalamt", SqlDbType.NVarChar).Value = total;
cmd.Parameters.Add("@date", SqlDbType.DateTime).Value = date.Split(',')[i];
cmd.Parameters.Add("@utno", SqlDbType.NVarChar).Value = utrno;
cmd.Parameters.Add("@paymentid",SqlDbType.NVarChar).Value=paymentid;
cmd.Parameters.Add("@paymode", SqlDbType.NVarChar).Value = modeofpayment;
cmd.Parameters.Add("@issuedate", SqlDbType.DateTime).Value = transferdate;
cmd.Parameters.Add("@sondate", SqlDbType.DateTime).Value = t;
cmd.Parameters.Add("@trainer", SqlDbType.NVarChar).Value = trainer;
cmd.Parameters.Add("@type", SqlDbType.NVarChar).Value = typeofadj;
cmd.Parameters.Add("@bank_id", SqlDbType.Int).Value = Convert.ToInt32(bnkid);
cmd.ExecuteNonQuery();
message = "Adjusted Amount Inserted Successfully";
con.Close();
}
}
我不知道什麼是錯的這個代碼Web服務,
這是我在Web服務進入
參數值ID:0特別是:0001 AMT:10 adjamt:10 tdate:
01-01-201 3,01-01-2013總數:20日期:2013年1月1日utrno:測試 modeofpayment:測試transferdate:2013年1月1日訓練者:IBRAHIM 篩海typeofadj:調整bnkid:
調用
和以下是錯誤
System.Data.SqlClient.SqlException: Error converting data type varchar to float.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at mvcerp2.newpayment.saverecd(String id, String particular, String amt, String adjamt, String tdate, String total, String date, String utrno, String modeofpayment, String transferdate, String trainer, String typeofadj, String bnkid) in Z:\mvcerp2\mvcerp2\newpayment.asmx.cs:line 135
請首先將這個減少到*僅僅是引起問題的參數 - 您可以發現,但我們不容易。另外,將來請花時間格式化代碼,不要有任何額外的縮進。它不需要很長時間就可以做到,但它在可讀性方面有所不同。 –
你的一個列是一個浮點數,你傳遞一個字符串。你甚至沒有看到錯誤信息? –
對不起,先生,這將記住下一篇文章 –