Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the MSDN Documentation:</p> <blockquote> <p>"Before you call Prepare, specify the data type of each parameter in the statement to be prepared. For each parameter that has a variable length data type, you must set the Size property to the maximum size needed. Prepare returns an error if these conditions are not met.</p> <p>If you call an Execute method after calling Prepare, any parameter value that is larger than the value specified by the Size property is automatically truncated to the original specified size of the parameter, and no truncation errors are returned.</p> <p>Output parameters (whether prepared or not) must have a user-specified data type. If you specify a variable length data type, you must also specify the maximum Size."</p> <p>Furthermore, "If the CommandType property is set to TableDirect, Prepare does nothing. If CommandType is set to StoredProcedure, the call to Prepare should succeed, ..."</p> </blockquote> <p>This in general is used to make sure that the end user is not using a SQL Injection technique to add or remove information you do not want them too from the database.</p> <p>I looked into it and check out this article <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.prepare.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.prepare.aspx</a>. Your issue is you need to define your parameters before you run .Prepare() and then set your parameters after you run .Prepare(). Right now you are doing both before. I would try something like this (Note I didn't test it so my syntax might be a bit off).</p> <pre><code>public static decimal pobierzBenchmarkKolejny(string varPortfelID, DateTime data, decimal varBenchmarkPoprzedni, decimal varStopaOdniesienia) { const string preparedCommand = @"SELECT [dbo].[ufn_BenchmarkKolejny](@varPortfelID, @data, @varBenchmarkPoprzedni, @varStopaOdniesienia) AS 'Benchmark'"; using (var varConnection = Locale.sqlConnectOneTime(Locale.sqlDataConnectionDetailsDZP)) //if (varConnection != null) { using (var sqlQuery = new SqlCommand(preparedCommand, varConnection)) { sqlQuery.Parameters.Add("@varPortfelID"); sqlQuery.Parameters.Add("@varStopaOdniesienia"); sqlQuery.Parameters.Add("@data"); sqlQuery.Parameters.Add("@varBenchmarkPoprzedni"); sqlQuery.Prepare(); sqlQuery.ExecuteNonQuery();//This might need to be ExecuteReader() sqlQuery.Parameters[0].Value = varPortfelID; sqlQuery.Parameters[1].Value = varStopaOdniesienia; sqlQuery.Parameters[2].Value = data; sqlQuery.Parameters[3].Value = varBenchmarkPoprzedni; using (var sqlQueryResult = sqlQuery.ExecuteReader()) if (sqlQueryResult != null) { while (sqlQueryResult.Read()) { } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload