我在處理類型轉換的麻煩......問題與類型的轉換
CODE:
public static string isLocalIncidentSubmitted()
{
string query = "SELECT Submit From [MVCOmar].[dbo].PrideMVCSubmitLog WHERE [email protected]";
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection(connectionStr4);
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.AddWithValue("@existingNum", MyGlobals1.secondversionDisplayTesting);
connection.Open();
SqlDataAdapter adp = new SqlDataAdapter(command);
adp.Fill(dt);
connection.Close();
command.Dispose();
connection.Dispose();
return dt.Rows[0]["Submit"].ToString();
}
表提交的類型爲varchar的
我得到一個大錯誤但這裏是它的前幾行:
System.Data.SqlClient.SqlException: Conversion failed when converting from a character string to uniqueidentifier. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.HasMoreRows()
如果你要問一個關於類型轉換的問題,如果您提供有關所涉及類型的更多詳細信息,它將非常有幫助...... –
ReportID只能包含36個字符串。 existingNum的長度也是36個字母,所以問題在於提交 – Bulvak
secondversionDisplayTesting是string類型,Submit列的類型是varchar,最大字符串長度是5. – Bulvak