|
see the code how i am creating place holder now. _Yoy has a formula used in excel.
private string _Yoy = @"IF(AND(ISNUMBER(C#),P#>0,NOT(ISERROR(C#/P#))),C#/P#-1,"""")";
public string YoY
{
get { return _Yoy; }
set { _Yoy = value; }
}
private void button1_Click(object sender, EventArgs e)
{
string strBMFormula = YoY.Replace("P#", "2005.13").Replace("C#", "7777.10");
}
I am replacing P# & C# with some value at runtime and program working as expected but i am doing this in large loop where Replace() function is getting called repeatedly which may increase memory use.
@"IF(AND(ISNUMBER(C#),P#>0,NOT(ISERROR(C#/P#))),C#/P#-1,"""")";
here i gave 4 double quote because there would two double quote in excel function.
i am using .Net version 4.5
so please suggest me how to create a place holder in string variable and put my value there without using Replace function.
i try this approach too but still no luck.
private void button1_Click(object sender, EventArgs e)
{
string strBMFormula = Replacement("A10", "Z210");
}
private string Replacement(string value1, string value2)
{
return @"IF(AND(ISNUMBER({value1}),{value2}>0,NOT(ISERROR({value1}/{value2}))),{value1}/{value2}-1,"""")";
}
|
|
|
|
|
I got fix for my above code. here it is.
private void button1_Click(object sender, EventArgs e)
{
string strBMFormula = Replacement("A10", "Z210");
}
private string Replacement(string value1, string value2)
{
return string.Format(@"IF(AND(ISNUMBER({0}),{1}>0,NOT(ISERROR({0}/{1}))),{0}/{1}-1,"""")",value1,value2);
}
|
|
|
|
|
You are confused with string modifiers. You are using the verbatim string modifier (@), which allows you to avoid having to escape special characters (no double-antislash, for example).
But you need the interpolated-string modifier, $ .
private string Replacement(string value1, string value2)
{
return $"IF(AND(ISNUMBER({value1}),{value2}>0,NOT(ISERROR({value1}/{value2}))),{value1}/{value2}-1,"""")";
}
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
string interpolation not available in my .net version. i am using c# v5.0 & VS2013.
|
|
|
|
|
First, what's stopping you from using later/latest versions of VS and FrameWork/C# ? Given those are free, why not upgrade ?
Try this:
const string YTemplate = @"IF(AND(ISNUMBER(C#),P#>0,NOT(ISERROR(C#/P#))),C#/P#-1,"""")";
StringBuilder sb = new StringBuilder(YTemplate);
sb = sb.Replace("P#", "2005.13").Replace("C#", "7777.10"); To reuse this, clear the StringBuilder after a use, and then reset its contents to 'YTemplate.
Faster, more efficient ? Lots of different opinions on String.Replace and StringBuilder.Replace: [^]
Do some tests with your data, and find out if it's better for your case.
And, keep your eye on the future: [^]
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
modified 20-Nov-21 0:09am.
|
|
|
|
|
I am doing this way and it works fine.
public static class StringHelpers
{
public static string BuildFormula(this string formulatemplate, string value1, string value2)
{
return string.Format(formulatemplate, value1, value2);
}
public static string BuildFormula(this string formulatemplate, string value1, string value2, string value3)
{
return string.Format(formulatemplate, value1, value2, value3);
}
}
Calling this way
---------------------
BrokerCountFormula = FormulaTemplate.BrokerCount.BuildFormula(
(StartPeriod + row.ToString()), (EndPeriod + row.ToString()));
|
|
|
|
|
I am doing this way and it works fine.
public static class StringHelpers
{
public static string BuildFormula(this string formulatemplate, string value1, string value2)
{
return string.Format(formulatemplate, value1, value2);
}
public static string BuildFormula(this string formulatemplate, string value1, string value2, string value3)
{
return string.Format(formulatemplate, value1, value2, value3);
}
}
Calling this way
---------------------
BrokerCountFormula = FormulaTemplate.BrokerCount.BuildFormula(
(StartPeriod + row.ToString()), (EndPeriod + row.ToString()));
|
|
|
|
|
Hi All,
As i am using below C# code in Asp.net web api(GET) to pull the records(8 lac records),i am facing an error i.e system.outofmemoryexception was thrown.Can anyone helpme out on this.Thank You.
public HttpResponseMessage GetLocation([FromBody] data data)
{
try
{
ds = objTransactionMgr.Getlocationdetails(data, ref objError);
if (ds.Tables[0].Rows.Count > 0)
{
var JsonList = ds.Tables[0].AsEnumerable().Select(dataRow => new get_location_details()
{
name = dataRow.Field<string>("name"),
order = dataRow.Field<string>("order"),
date = Convert.ToDateTime(dataRow.Field<datetime?>("date")),
location = dataRow.Field<string>("location"),
type = dataRow.Field<string>("type"),
id = dataRow.Field<string>("id"),
category = dataRow.Field<string>("category"),
seq = Convert.ToInt32(dataRow.Field<decimal?>("seq")),
address = dataRow.Field<string>("address"),
uom = dataRow.Field<string>("uom"),
volume = dataRow.Field<string>("volume"),
total = Convert.ToInt32(dataRow.Field<double?>("total")),
task_value = Convert.ToInt32(dataRow.Field<decimal?>("task_value"))
}).ToList();
return Request.CreateResponse(HttpStatusCode.OK, JsonList);
}
else
{
_messages.status = "Success";
_messages.message = "No rows to return";
return Request.CreateResponse(HttpStatusCode.OK, _messages);
}
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
|
|
|
|
|
Simple: don't load so much data.
Either reduce the amount of data your API is returning, or stream the results from the database[^] instead of trying to load them all into memory at once.
NB: If you go with the streaming option, you'll just be moving the error to the client, which won't be able to load the entire response from your API into memory.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard Thank you for your time.
As my client is looking for all the data at once and stream the results from database means what exactly
can u bit explain pls
|
|
|
|
|
Your Getlocationdetails method is currently loading everything into a DataSet . You would need to use a SqlDataReader instead, and write the records to the response as you read them.
Something like this:
public async Task<HttpResponseMessage> GetLocation([FromBody] data data)
{
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new PushStreamContent(async (outputStream, httpContext, transportContext) =>
{
using (var sw = new StreamWriter(stream))
using (var jsonWriter = new JsonTextWriter(sw))
using (SqlConnection connection = CreateConnection())
using (SqlCommand command = new SqlCommand("...", connection))
{
... ADD PARAMETERS HERE ...
await connection.OpenAsync();
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
{
var serializer = new JsonSerialize();
serializer.Serialize(writer, new { status = "Success", message = "No rows to return" });
return;
}
writer.WriteStartArray();
while (await reader.ReadAsync())
{
writer.WriteStartObject();
writer.WritePropertyName("name");
writer.WriteValue(reader["name"]);
writer.WritePropertyName("order");
writer.WriteValue(reader["order"]);
writer.WritePropertyName("date");
writer.WriteValue(reader["date"]);
...
writer.WriteEndObject();
}
writer.WriteEndArray();
}
}
})
};
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you sooo much for your time Richard i will try and get back to you.
|
|
|
|
|
I am trying to communicate with a EOS Rebel T7 on mac, but haven't had any luck.
I downloaded the latest version of the SDK, but could not test the Objective-C sample because I don't (can't yet) have Xcode on my computer.
I found this C# project to be instructive. Ultimately I was able to get the following C# code to compile without errors:
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using EOSDigital.API;
using EOSDigital.SDK;
namespace ConsoleExample
{
class Program
{
static CanonAPI APIHandler;
static Camera MainCamera;
static string ImageSaveDirectory;
static bool Error = false;
static ManualResetEvent WaitEvent = new ManualResetEvent(false);
static void Main(string[] args)
{
CanonSDK.InitializeVersion();
IntPtr camPtrList;
CanonSDK.EdsGetCameraList(out camPtrList);
int camCount;
CanonSDK.EdsGetChildCount(camPtrList, out camCount);
Console.WriteLine(camCount + " cameras found.");
}
}
}
However, I end up with camCount==0; "0 cameras found". I thought this might be because the EOS Utility (which opens automatically when plugging in the camera) is occupying the necessary resources, however I tried uninstalling EOS Utility and this did not help.
Can anyone provide a simple example that I can test (that doesn't require Xcode) in VS or VScode? Any help or advice would be much appreciated. Thank you!
PS: Figuring out how to compile in VS on mac was a struggle as I am unfamiliar with both, so I'm open to any suggestions for other IDEs/compilers/languages if it will make using EDSDK easier.
|
|
|
|
|
I'm unfamiliar with Canon EDSDK however I found this article[^] on this very site; the article has lots of high votes, but please don't expect it to make your job simpler...
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
|
|
|
|
|
Hello,
First of all, I would like to inform you that I am not a software developer, I am dealing with it as a hobby.
I made a simple desktop application, there is a picturebox on the form, I want a website to be opened when I click on the picture, but it gives an error. I've been searching for a few days, there are similar issues but no answer.
Methods I have tried.
using System.Diagnostics;
private void pictureBox2_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(@"https://www.website.com.tr/");
}
The error the codes give is "System.ComponentModel.Win32Exception: 'The system cannot find the file specified.' "
Error details.
System.ComponentModel.Win32Exception
HResult=0x80004005
İleti=Sistem belirtilen dosyayı bulamıyor.
Kaynak=System.Diagnostics.Process
StackTrace:
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName)
at AcınımHepalama_001.Form1.pictureBox2_Click(Object sender, EventArgs e) in D:\ÖMÜR ÇALIŞMALAR\MU-uygulamarı\AcınımHepalama-001\Form1.cs:line 604
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
|
|
|
|
|
Try:
System.Diagnostics.Process.Start("explorer.exe", @"https://www.website.com.tr/");
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
thank you very much this code worked.
|
|
|
|
|
You're welcome!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Thanks for the reply, I'll look into the thread you mentioned.
|
|
|
|
|
You included expected results vs. actual results. You included actual exception.
Well done
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
i am just starting with c# and wondering if there is a way to read the contents of csv files stored in a particular folder on network and write it into an oracle table. Can someone give me an example so that i can try and test by myself.
|
|
|
|
|
|
To add to what Richard has said, there are several CSV reading packages - this one reads into a DataTable, so provided the columns match up with your database, they can be INSERTed with no other changes: A Fast CSV Reader[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
The article I linked to also reads into a DataTable.
|
|
|
|
|