|
Member 15923846 wrote: online examination system
Then you will not be doing it in C#. At least not the UI part.
I suppose a true formal testing system would need to retrieve the time from a server and show that. But for a simple system you can probably find something in javascript that does that.
|
|
|
|
|
What is the difference between the following, or is there anything?
public async Task SomeFunc()
{
await Task.Run(() =>
{
var reader = com.ExecuteReader();
...
}
}
public async Task SomeFunc()
{
var reader = await com.ExecuteReaderAsync();
....
}
|
|
|
|
|
Quite a significant difference.
In the first example, you essentially spin up a new thread, block that thread waiting for a synchronous network call to complete, and sign up the calling thread to be notified when the new thread completes. Whilst it may sometimes be useful for keeping a desktop UI responsive, it's not great for performance.
In the second example, you kick off an asynchronous network call, and sign up the calling thread to be notified when that call completes. That's a much more efficient approach.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Greetings experts,
The following is a linq to sql code that I am trying to convert to for lack of a better work, regular .net framework code:
protected void updateSal_Click(object sender, EventArgs e)
{
newTotal.Text = theLinq.Salary.Single(s => s.Salary_Year == DateTime.Now.Year).Total_Salary.ToString();
}
'//This is my attempted conversion to vb.net
Protected Sub updateSal_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim rowsAffected As Integer
Dim currYear As Integer = Date.Now.Year
Using con As New SqlConnection("server=.;database=Test;integrated security=true")
Using cmd As New SqlCommand("UPDATE Salary Set Total_Salary=@totsal WHERE Salary_Year = @currentYear", con)
cmd.Parameters.Add("@totsal", SqlDbType.Decimal).Value = newTotal.Text
cmd.Parameters.Add("@currentYear", SqlDbType.Integer).Value = currYear
con.Open()
rowsAffected = cmd.ExecuteNonQuery()
End Using
End Using
End Sub
My result is coming up empty even though the update code works when I run it in SSMS.
Am I doing the conversion incorrectly.
modified 9-Feb-23 0:23am.
|
|
|
|
|
The LINQ code is not an UPDATE query. It's a SELECT, and one that doesn't make much sense.
The LINQ query is selecting a single record from a possible list of records where Salary_Year matches the current year. The returned record better have a Total_Salary field to return a string for.
|
|
|
|
|
WOW!
But you can understand why I was confused.
The method says Update(...)
Thank you.
|
|
|
|
|
The thing is, what is the method updating? In this case, it looks like it's updating the UI, not the database.
|
|
|
|
|
Thank you so very much Dave for the prompt response.
|
|
|
|
|
samflex wrote: The method says Update(...) No, it says updateSal_Click(object sender, EventArgs e) , which is clearly an event handler that is called when the user clicks a button or other control. And the result of the LINQ query is returned in the Text field of the newTotal item, which is most likely a field on the form.
|
|
|
|
|
i advised an article writer (newbie), here, that his use of the above syntax is not a good programming practice.
my thought is why would you have a potentially 'newable class (since it gets a default constructor) where calling 'new meant a "useless" instance.
thinking that over ... given VS and ReSharper don't flag that ,,, i lean towards thinking maybe during development: who cares, as long as it compiles; you might want to add 'public stuff later, but, for production code, that is a code smell.
i have never used that syntax, and never put a static class in a public class, either.
your thoughts ?
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
modified 8-Feb-23 20:13pm.
|
|
|
|
|
My feeling is that overuse of static generally means they don't understand OOPs properly - it's often a "it worked in C" approach to an app rather than using objects to avoid unnecessary globals (both methods and variables)
If he's a coding newbie, it's likely that his tutor grew up in a procedural environment and has just learned the syntax of an OOPs language rather the principles behind it.
"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!
|
|
|
|
|
I don't see the point of creating a singleton when there is a class that will never be a component of anything else. My apps usually have some sort of "data repository" in memory that needs to be accessed from all over the app; a static class is supremely convenient in this case. "Static" doesn't define the data; it only defines the "references". They could all be observable collections with different subscribers. Dependency injection in this case is obsessing (IMO).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
If it makes sense as a “bundle” of statics, then make the constructor private.
If it is more class-like, then a singleton would make it easier to substitute a different implementation later.
I agree with you that it should be last resort and usually a code smell.
|
|
|
|
|
i have been using cliwrap for running git commands and passing the arguments. But it seems to have failed while running my msbuild command from my c# console application.
What i am trying-
var stdOutSetup = new StringBuilder();
var stdErrSetup = new StringBuilder();
var Setup = await Cli.Wrap("msbuild")
.WithArguments("/t:scmclean && /t:setup")
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutSetup))
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrSetup))
.ExecuteBufferedAsync();
var stdOut2 = stdOutSetup.ToString();
var stdErr2 = stdErrSetup.ToString();
Console.WriteLine("Build Commands Output :");
Console.WriteLine(stdOut2);
Console.WriteLine(stdErr2);
is there any possible way where i can run msbuild commands from my c# console application?
|
|
|
|
|
Yes, you just have to supply the correct command line to run MsBuild. You don't say what the error is that you're getting back, and that's really important when troubleshooting problems.
My guess is going to be you're not supplying the path to MsBuild and/or you're not supplying any required command line parameters for it to know what you want to do.
AND STOPP SPAMMING THE SITE WITH THE SAME QUESTION OVER AND OVER AGAIN!
|
|
|
|
|
Open a console window that represents the OS shell (console) that your command is supposed to be running in. Open in the root directory.
Then type the following. It will fail I am sure. It will not work in your program until you can get it to run from the shell.
msbuild /t:scmclean && /t:setup
I did not investigate it too much but I am rather certain that however you are doing it (which shell) that that '&&' is wrong.
|
|
|
|
|
I have tried running msbuild /t:scmclean from my command prompt, it works fine , but when i try to call the same command from my c# console application using the code below
namespace BuildCode
{
class BuildCM
{
public static void Main()
{
Process msetup = new Process();
msetup.StartInfo.FileName = "cmd.exe";
msetup.StartInfo.CreateNoWindow = true;
msetup.StartInfo.RedirectStandardInput = true;
msetup.StartInfo.RedirectStandardOutput = true;
msetup.StartInfo.UseShellExecute = false;
msetup.Start();
msetup.StandardInput.WriteLine("msbuild.exe D:\\git\\btf_pi_testrack\\Build\\Tools /t:scmclean");
msetup.StandardInput.Flush();
msetup.StandardInput.Close();
msetup.WaitForExit();
Console.WriteLine(msetup.StandardOutput.ReadToEnd());
Console.ReadKey();
}
}
}
i get an error:
C:\Users\JediAdmin\source\repos\msbuild\bin\Debug\net7.0>msbuild.exe D:\git\btf_pi_testrack\Build\Tools /t:scmclean
MSBuild version 17.4.0+18d5aef85 for .NET
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file., it fails to run msbuild command for the particular directory
but if i execute msbuild.exe D:\git\btf_pi_testrack\Build\Tools /t:scmclean in command prompt, it works fine.
Also i did a little bit of digging for this issue and came back with Microsoft.Build.Runtime and Microsoft.Build.utilities.core for running msbuild commands from console application, however i couldn't get any code example to understabd how it does that? any idea on this as well?
|
|
|
|
|
Madhurima Dutta wrote: msbuild /t:scmclean
First I doubt it ran find from the root directory.
Second that is not the command that you are attempting to run in the code you originally posted.
Third what you posted here does not match what msbuild documentation expects.
MSBuild Command-Line Reference - MSBuild | Microsoft Learn[^]
|
|
|
|
|
This is Model Class
public class CartInfo
{
[Key]
public int S_NO { get; set; }
public virtual int Bill_Id { get; set; }
public virtual int Ship_Id { get; set; }
public virtual int Product_Id { get; set; }
[ForeignKey("Product_Id")]
public List<Products> Products { get; set; }
public int Sub_Total { get; set; }
public int Product_Quantity { get; set; }
}
[Table("Product_Detail")]
public class Products
{
[Key, Column(Order = 0)]
public int Product_Id { get; set; }
public string Product_Code { get; set; }
public string Product_Name { get; set; }
public int Unit_Price { get; set; }
}
Insert command
string code = (model.Cart[i]).Products[0].Product_Code;
var _products = (from p in db.Products where p.Product_Code ==code select p).FirstOrDefault();
int Product_Id = _products.Product_Id;
CartInfo cart = new CartInfo();
cart.Bill_Id = Bill_Id;
cart.Ship_Id = Ship_Id;
cart.Product_Id = Product_Id;
cart.Products = new List<Products>();
var pf = new Products();
pf.Product_Code = (model.Cart[i]).Products[0].Product_Code;
pf.Product_Name = (model.Cart[i]).Products[0].Product_Name;
pf.Unit_Price = (model.Cart[i]).Products[0].Unit_Price;
cart.Products.Add(pf);
cart.Product_Quantity = (model.Cart[i]).Product_Quantity;
cart.Sub_Total = (model.Cart[i]).Sub_Total;
db.Cart_Details.Add(cart); <big></big>
db.SaveChanges();
|
|
|
|
|
The exception says you can't put a product where a list of products is expected. CartInfo specifies it as a list of products.
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.
|
|
|
|
|
A "Product" is single; products is plural.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I have extended a class from ListCollectionView for Data Virtualizing. I am able to load after taking reference from this article - Data Virtualization using DataGrid[^] but I am not able to add GroupDescriptions in DataGrid.
Please suggest, what I need to do?
|
|
|
|
|
Don't post this under generic forums - if you got the code from an article, then there is a "Add a Comment or Question" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
"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!
|
|
|
|
|
I did that but not yet received answer so posting here.
|
|
|
|