|
Dear Sir,
Thank you for your response and pointing on parameter. I focused on parameter and
I found out the error in my code
public DataTable GetMiti()
{
SqlParameter[] param = new SqlParameter[]
{
new SqlParameter("@engdate", _engdate)
};
return DAO.GetTable("spGetMiti", null);
}
return DAO.GetTable("spGetMiti", null);
I corrected it
return DAO.GetTable("spGetMiti", param);
|
|
|
|
|
Which is what I explained in my first reply.
|
|
|
|
|
My requirement is straight forward. i have Http://abc need to make it Https://abc . I have added the folowing code in web.config. i.e. added new rule in IIS. I have folowwed the URL rewriting module in IIS.
<rewrite>
<rules>
<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^off$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
</rule>
</rules>
</rewrite>
It's not working .
|
|
|
|
|
And what does that have to do with C#?
Ask here: Ask a Question[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This is the code form web.config. Just formatted for proper code view. If you know the answer then Helpout.
|
|
|
|
|
And (I ask again) what does that have to do with C#?
This is a dedicated forum: C# only. QA is more general, it takes queries on many, many subjects.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
i want to raise an exception when the user enters an alt keywords like({,Ñ,º,ô) in xml with c# code. the exception has to be raised from loadxml()
|
|
|
|
|
Don't post the same question in multiple places: it duplicates work and that annoys people.
You already have an answer in QA, so leave it there.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'm having a dickens of a time trying to instantiate the VCCodeModel interface. This is part of the Visual Studio object model. I eventually want to extract type information from a C++ project directly from Visual Studio.
First I locate the Visual C++ project in the solution, and then I get a reference to the Project object.
The problem is when I try to cast the Project.CodeModel interface to a VCCodeModel interface, which is what they say to do in the documentation[^].
The error that I receive is:
'Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.VisualStudio.VCCodeModel.VCCodeModel'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A590E96B-CC8C-48AF-9E8F-7C3FE7865586}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).' This is interesting because the GUID in the error message is not the GUID given by the documentation for the VCCodeModel interface! The correct GUID is {E6691CDE-9A41-4891-8D8C-C1E93958E6A0}
Does anyone know what's going on here? Why can't I retrieve the VCCodeModel interface as they do in the docs, and why does it try to cast it to the wrong IID ?
My code is below. I'm using Visual Studio 2017.
private void buttonExtract_Click(object sender, EventArgs e)
{
EnvDTE80.DTE2 dte2 =
(DTE2) System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.15.0");
int Count = dte2.Solution.Projects.Count;
Project P = null;
Project FW32 = null;
for (int a = 1; a <= Count; a++)
{
P = dte2.Solution.Projects.Item(a);
if (P.FullName.Contains("ConsoleApplication"))
{
break;
}
}
VCCodeModel vcCodeModel = (VCCodeModel) P.CodeModel;
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Using linq or TSQL (I have not decided where to put the function) is there an elegant way of getting the average percentage change between a list of decimals'
I can only think of the sledge hammer method of looping through each, getting the percentage of change for each and then averaging the results. A cursor or CTE in TSQL and a foreach loop in c# (already done but it feels like a kludge).
100
120 ---------- 0.166666667 ==(120-100)/120
118 --------- -0.016949153
126 ---------- 0.063492063
134.9548023 0.071069859
144.5460211
The goal is to extend the series of 4 numbers to 6 by applying the average of the change of the first 4 numbers.
Never underestimate the power of human stupidity
RAH
modified 27-Aug-17 4:20am.
|
|
|
|
|
return ( 42 ) ; should be enough for anyone.
For SQL Server, how about a CLR aggregate?
|
|
|
|
|
Takes me 2 minutes to write the bloody thing in excel and it is still a kludge. The business will NOT accept 42 (and most would not know the reference, damned whippersnappers).
DBA/policy refuses to add the CLR to SQL Server.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The Bosses where I am have now seen the performance benefits of CLR Functions in place of string manipulation in SQL (as a particularly strong argument).
I spent the last two weeks refactoring my CLR Functions so more teams can easily deploy my Library database to their servers.
By using a separate database for this library of Functions, we don't need to enable the CLR on the databases that contain data.
Then try to convince the admins that they don't need to enable backups on a database that contains no data.
The biggest issue I've encountered is in deploying updates for the Assembly, but my friendly DBA and I seem to have a working solution.
|
|
|
|
|
Got some sample data and expected result?
|
|
|
|
|
Edited the OP with some actual data.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The percentage of change defined as ... ?
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it. A few hundred years later another traveler despairing as myself, may mourn the disappearance of what I may have seen, but failed to see.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
No idea how to express it in LINQ or TSQL, but I think this is the maths you're looking for (assuming the users don't mind logarithms)
Using your numbers A0 = 100, A1, A2, A3 = 126, produce A4, A5.
ratio = cube-root(A3 / A0)
A4 = A3 * ratio, etc
Disclaimer: A career in engineering taught me to think logarithmically, ratios not increments, etc.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Assuming SQL Server 2012 or later, and the existence a field in your table which defines the order in which you want to process the rows:
WITH cte As
(
SELECT
ROW_NUMBER() OVER (ORDER BY SeqNo) As RN,
(TheValue - LAG(TheValue) OVER (ORDER BY SeqNo)) / TheValue As Change
FROM
YourTable
)
SELECT
Avg(Change) As AverageChange
FROM
cte
WHERE
RN Between 1 And 4
;
Result (using decimal(20, 7) for the source column type): 0.07106985920545242
For C#, using LINQ:
double average = values.Skip(1).Take(3)
.Zip(values, (second, first) => (second - first) / second)
.Average();
Result (using decimal type): 0.0710698592054524257914088423
Result (using double type): 0.0710698592054524
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Your name is getting into my code base. I like to link back to these answers as the make excellent doco The final function...
private List<decimal> CalcAverageGrowth(List<decimal> lValues)
{
List<decimal> lResult = new List<decimal>();
decimal average = lValues.Skip(1).Take(lValues.Count - 1)
.Zip(lValues, (second, first) => (second - first) / second)
.Average();
lResult.Add(lValues.Last() + (lValues.Last() * average));
lResult.Add(lResult.Last() + (lResult.Last() * average));
return lResult;
}
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote:
lValues.Skip(1).Take(lValues.Count - 1)
There's no need for the Take there. You're saying "skip one, and take the rest", which is exactly what would happen if you just said "skip 1".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Any idea how to deal with a zero value in the source list - generates a divide by zero error. Other than filter them out.
I hate crappy data
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Taking the example below, this should do it:
Values.Select(
p =>
new
{
avg = Values.Skip(1).Take(Values.Count - 1)
.Where(x => Math.Abs(x) > double.Epsilon)
.Zip(Values, (second, first) => (second - first)/second)
.Average()
})
.Select(x => new {x, last = Values.Last()})
.Select(@t => new {@t, aver = @t.last + (@t.last*@t.x.avg)})
.Select(@t => new {value1 = @t.aver, value2 = @t.aver + (@t.aver*@t.@t.x.avg)}).First();
This space for rent
|
|
|
|
|
It depends what you want the percentage change to be when one of the values is zero.
Assuming you want it to be 1 , the ternary operator should do the trick:
decimal average = lValues.Skip(1)
.Zip(lValues, (second, first) => second == 0 ? 1 : (second - first) / second)
.Average();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The evil side in me likes a challenge. I had a little bit of a play around and came up with this (where we assume that Values is your list of double value inputs; this copes with arbitrary lengths of Values as long as it's greater than 2):
Values.Select(
p =>
new {avg = Values.Skip(1).Where(x => index < Values.Count).Select(x => (x - Values[index++])/x).Average()})
.Select(x => new {x, last = Values.Last()})
.Select(@t => new {@t, aver = @t.last + (@t.last*@t.x.avg)})
.Select(@t => new {value1 = @t.aver, value2 = @t.aver + (@t.aver*@t.@t.x.avg)}).First(); Taking inspiration from Richard's excellent answer, this can be further simplified into:
Values.Select(
p =>
new
{
avg = Values.Skip(1).Take(Values.Count - 1)
.Zip(Values, (second, first) => (second - first)/second)
.Average()
})
.Select(x => new {x, last = Values.Last()})
.Select(@t => new {@t, aver = @t.last + (@t.last*@t.x.avg)})
.Select(@t => new {value1 = @t.aver, value2 = @t.aver + (@t.aver*@t.@t.x.avg)}).First();
This space for rent
modified 29-Aug-17 10:25am.
|
|
|
|
|
Dear experts
I am somewhat "c++ corrupted". With this background I'm looking for a replacement for c++ const stuff in c#.
I don't look for a solution. First and foremost, this question I ask to get an assessment of the class design from you.
What I need/I try to solve:
I have a class Spectrum (basically a vector of doubles) for which I need full access for some tasks of the app(means manipulate each value of the vector) while other tasks should only have the possibility to read the values.
public class Spectrum
{
private readonly List _values;
public double this[int lambda]
{
get
{
return _values[lambda];
}
set
{
_values[lambda] = value;
}
}
}
[Edit]
The target is to protect some data from unintentional/Programme mistaken modifications
[/Edit]
Approach I.
For a first approach I thought I introduce an interface IConstSpectrum which hides the setter and will be used where I like to return a read only Spectrum.
But like in c++ one can cast the interface and have afterwards full access (in c++ this means a dirty const_cast)
Approach II.
a.) I introduce a class ConstSpectrum ...
public class ConstSpectrum
{
protected readonly List _values;
public double this[int lambda]
{
get
{
return _values[lambda];
}
}
}
b.) ... and derive from this the full accessible spectrum
public class Spectrum: ConstSpectrum
{
public double this[int lambda]
{
set
{
_values[lambda] = value;
}
}
}
Conclusion Approach II:
Depending on the task , I would use ConstSpectrum or Spectrum. And I'm Aware returning a Spectrum as ConstSpectrum opens the door to cast again.
Questions, resp, how do you see this:
- What do you think about this design? Is it overkill?
- Is there a better or maybe more easy solution?
Thank you very much in advance.
Bruno
modified 19-Jan-21 21:04pm.
|
|
|
|