2番目の最後の行のExecuteNonQueryでエラーが発生しました。入力文字列の形式が正しくありません
Errormassage: にSystem.FormatException:入力文字列が正しい形式ではありませんでした
Aの.NET Frameworkエラーは、ユーザー定義のルーチンまたは集計 "sp_InsertShuttleCount" の実行中に発生しました。 にSystem.FormatException:AtsProceduresでSystem.Number.ParseInt32(Stringを、NumberStylesスタイル、のNumberFormatInfo情報)でSystem.Number.StringToNumberで (文字列str、NumberStylesオプション、NumberBuffer &数、のNumberFormatInfo情報、ブールparseDecimal) 。 InsertShuttleErrorCount(SqlStringシャトル、SqlStringステーション、SqlStringエラーステート、SqlStringネスト、SqlStringエラーネスト、SqlDateTime ts)
スタックトレース:System.Data.SqlClient.SqlInternalConnection.OnError(SQLException例外、ブールbreakConnection)でSystem.Data.SqlClient.SqlConnection.OnError(SQLException例外、ブールbreakConnection) で
System.Data.SqlClient.SqlCommand.FinishExecutでSystem.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() でSystem.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior、SqlCommandオブジェクトcmdHandler、SqlDataReaderのデータストリーム、BulkCopySimpleResultSet bulkCopyHandler、TdsParserStateObject stateObj)で eリーダー(SqlDataReaderのDS、RunBehavior runBehavior、文字列resetOptionsString)System.Data.SqlClient.SqlCommand.RunExecuteReaderTdsで (CommandBehaviorのcmdBehavior、RunBehavior runBehavior、ブールreturnStream、ブール非同期)System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehaviorのcmdBehaviorで 、 ATS_Test_Data_GeneratorでSystem.Data.SqlClient.SqlCommand.ExecuteNonQueryでrunBehavior runBehavior、ブールreturnStream、文字列方法、DbAsyncResult結果) System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult結果、文字列methodNameの、ブールsendToPipeで) () 。 ATS_Test_Data_Generator \ ATS_Test_Data_Generator \ Form1.cs:Form1..ctor()C:\ Code \ ATSBDE \ c#\ ATS_Test_Data_Generator.Program.Main()の行113 をC:\ Code \ ATSBDE \ c#\に生成します。 \ ATS_Test_Data_Gen erator \ ATS_Test_Data_Generator \のProgram.cs:System.AppDomain.ExecuteAssembly(文字列assemblyFile、証拠assemblySecurity、文字列[]引数)Microsoft.VisualStudioで でSystem.AppDomain._nExecuteAssembly(RuntimeAssemblyアセンブリ、文字列[]引数) におけるライン18 .HostingProcess.HostProc.RunUsersAssembly()System.Threading.ExecutionContext.RunでSystem.Threading.ThreadHelper.ThreadStart_Context(オブジェクトの状態)で (のExecutionContextのExecutionContext、ContextCallbackコールバック、ブールignoreSyncCtxの状態オブジェクト) System.Threading.ExecutionContextで.Run(ExecutionContext executionContext、ContextCallbackコールバック、オブジェクト状態) at System.Threading.ThreadHelper。ThreadStart()ストリング
駅の
値:0; 5; 10; 15; 20; 30; 35; 40; 55; 60; 65; 70; 80; 85; 90; 100; 110; 120; 125;
エラーステーション:5,3; 4; 4; 6; 6; 4; 5; 4; 4; 6; 4; 4; 5; 5; 4; 5; 3; 5; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; 1 | 2 | 3 | 4 | 5 | 6 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 0; 0 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 1; 1 | 1 | 0 | 0 | 0 | 1 | 1 | 0; 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 0; 1 | 1 | 1 | 0 | 0 | 0 | 1 | 1;
Dが日時である:d.ToString() "2012年2月10日午前6時01分00秒" が文字列
ストアドプロシージャは4 NVARCHAR(4000)を受け取り、1日時が格納され
for (int i = 0; i <= 16; i++) {
String Stations="";
String ErrorStations = "";
String Nests = "";
String ErrorNests = "";
command = new SqlCommand(null, connection) {
CommandText = "ats.sp_getStations",
CommandType = CommandType.StoredProcedure
};
SqlDataReader reader = command.ExecuteReader();
int k = 0;
while (reader.Read()) {
Stations += reader.GetInt32(0)+";";
Nests += "1|2|3|4|5|6|7|8;";
int m=0;
for (int j = 0; j < 8; j++) {
int l;
l=r.Next(0, 2);
nestcounts[i, k, j] += l;
m += l;
if(j!=7)
ErrorNests += nestcounts[i, k, j] + "|";
else
ErrorNests += nestcounts[i, k, j] + ";";
}
stationcounts[i, k] += m;
ErrorStations += stationcounts[i, k] + ";";
k++;
}
reader.Close();
command.Dispose();
command = new SqlCommand(null, connection) {
CommandText = "exec dbo.sp_InsertShuttleCount @shuttle, @stations, @errorstations, @nests, @errornests, @ts",
};
command.Parameters.Clear();
command.Parameters.Add("@shuttle", SqlDbType.NVarChar, 4000).Value = "1";
command.Parameters.Add("@stations", SqlDbType.NVarChar, 4000).Value = Stations;
command.Parameters.Add("@errorstations", SqlDbType.NVarChar, 4000).Value = ErrorStations;
command.Parameters.Add("@nests", SqlDbType.NVarChar, 4000).Value = Nests;
command.Parameters.Add("@errornests", SqlDbType.NVarChar, 4000).Value = ErrorNests;
command.Parameters.Add("@ts", SqlDbType.DateTime).Value = d;
command.ExecuteNonQuery();
command.Dispose();
}
値手順
これは頻繁に使用されるため、うまく動作するCLR手順です。もちろん、5つのNvarcharsがタイプミスです。
PROCEDURE [DBO]。[sp_InsertShuttleCount] @shuttle NVARCHAR、 @stationsのNVARCHAR、 @errorstationsのNVARCHAR、 @nestsのNVARCHAR、 @errornestsのNVARCHAR、 @ts [日時]をCREATE WITH CALLER AS EXECUTE EXTERNAL NAMEようATS-CLR]。[AtsProcedures]。[InsertShuttleErrorCount] GO
EXEC sys.sp_addextendedpropertyする@名= N'SqlAssemblyFile '@値= N'AtsProcedures.cs'は、@ level0type = N' SCHEMA '、@ level0name = N'dbo'、@ level1type = N'PROCEDURE '、@ level1name = N'sp level0name = N'dbo @ _InsertShuttleCount ' GO
名= N'SqlAssemblyFileLine @ EXEC sys.sp_addextendedproperty' level0type = N'SCHEMA @、 '値@ = N'51' 、'、level1type = N'PROCEDURE @ '、@ level1name = N'sp_InsertShuttleCount' GO
私のコードに間違いがありますか?
ストアドプロシージャも同様に投稿できますか?そこに問題があるかもしれません。 – aaronj
はい。そして、それは4 nvarcharsと1 datetime、またはそのtypoでしたか?あなたは6つの引数で呼び出し、そのうちの5つはnvarcharsです。 –