|
OK, I get it now.
That book I referenced doesn't show any of this, so far. Now I get why nothing was happening when I ran my console app. I was under the impression that creating the DBContext would do all of this
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
In a production environment, you would NEVER hardcode a connection string. This would prevent you from developing against a dev version of the database and testing code and migrations without impacting the production database.
Read the entire section on Migrations, not just the Overview:
Migrations Overview - EF Core | Microsoft Learn[^]
|
|
|
|
|
Ya, I Put it there just for testing.
Thanks for all your help
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Have you checked the file permissions for the database? I suppose that for a Trusted Connection that is not relevant.
Can you open the database using that connection string in SSMS, or VS I suppose?
modified 24-Nov-22 17:59pm.
|
|
|
|
|
No I didn't check.
There is no DB. EF is supposed to create ut
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hello.
Can someone help me with source codes on how to append a QRCode to an already existing PDF file located somewhere in a folder. I have tried but its clearing the available content on the already existing PDF file. I dont want it to clear. I just want it to append the QRCode to the existing content on the existing PDF File.
//GeneratedPdf generatedPDF = new GeneratedPdf();
Document document = new Document();
string path = @"C:\Setups\To Process\";
string originalFileName = "myTestPDFFile.pdf";
PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream(path + originalFileName,
FileMode.Append));
document.Open();
string strBarCodeValue = "https://mytest.com/my-Portal/invoiceChk.htm?
actionCode=loadPage&invoiceNo=0885434";
BarcodeQRCode barcodeQRCode = new BarcodeQRCode(strBarCodeValue, 120, 120, null);
document.Add(barcodeQRCode.GetImage());
document.Close();
|
|
|
|
|
Fezih5 wrote:
PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream(path + originalFileName, FileMode.Append)); That simply appends a brand new PDF file to the end of the original file. The result will not be a valid PDF file.
You need to read the existing PDF file into memory, and then modify it.
The documentation for the Java iText library, on which iTextSharp is based, has this example:
Chapter 5: Manipulating an existing PDF document[^]
Hopefully the libraries won't have diverged too much, so you should be able to work out how to translate that to the iTextSharp version.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello someone help me to find a C# program that counts the numbers of triangles in a Graph
thanks so much.
|
|
|
|
|
We're not a Google service for you. You 're perfectly capable of "finding" your own results.
The problem with your question is what do you mean by "counts the number of triangles in a Graph." What's a "graph" in your app? How is the data represented?
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?
That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!
Just saying "counts the numbers of triangles in a Graph" means nothing to us without context: and even if it did, there are other problems:
1) We aren't here to do your homework
2) Your teacher is almost certainly aware of sites like this, and handing in code you "found on the internet" as your own work is called plagiarism: and the punishment for that can include expulsion from your school. Even if it doesn't, unless you write your own code, you won't learn how to - which means you will fail your final exams. Think about it: you can watch as much Tour de France as you want - it still won't teach you how to ride a bicycle!
"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!
|
|
|
|
|
You should be able to figure it out from the data if you understand what the "markers" represent; e.g. daily hi / lo.
If you don't understand what the markers represent, counting them is pointless.
"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
|
|
|
|
|
Hi,
I am trying to insert into sql from Dynamic object ,
But insert failed with date type values,
Can some one suggest how can I handle this situation please.
command.CommandText = "INSERT INTO table VALUES (" + "'" + string.Join("',' ", ((IDictionary<string, object="">)rec).Values) + "')";
here are object variable dates I am passing
[4] {31/05/2022 23:00:00 +00:00} object {System.DateTimeOffset}
[11] "2022-10-25 16:12:27" object {string}
|
|
|
|
|
|
Don't do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood' The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable; Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x'; A perfectly valid SELECT
DROP TABLE MyTable; A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
"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!
|
|
|
|
|
As Griff said, your code is vulnerable to SQL Injection[^].
Fixing it to use parameters isn't too hard:
StringBuilder sb = new StringBuilder("INSERT INTO table VALUES (");
foreach (object value in ((IDictionary<string, object>)rec).Values)
{
if (command.Parameters.Count != 0) sb.Append(", ");
string name = "@V" + command.Parameters.Count;
command.Parameters.AddWithValue(name, value);
sb.Append(name);
}
sb.Append(");");
command.CommandText = sb.ToString();
However, this may still not work. You haven't specified the list of columns you want to insert into. And there's no guarantee that the dictionary's Values collection will return the values in the same order as the columns of the table. So you could end up trying to insert the wrong value into the wrong column, which will either result in an error, or in data corruption.
Assuming the keys of your dictionary match the column names from your table, you'll want something more like this:
StringBuilder columnsList = new StringBuilder();
StringBuilder valuesList = new StringBuilder();
foreach (KeyValuePair<string, object> item in (IDictionary<string, object>)rec)
{
if (columnsList.Length != 0) columnsList.Append(", ");
if (valuesList.Length != 0) valuesList.Append(", ");
string name = "@" + item.Key;
command.Parameters.AddWithValue(name, item.Value);
columnsList.Append(item.Key);
valuesList.Append(name);
}
command.CommandText = "INSERT INTO table (" + columnsList + ") VALUES (" + valuesList + ");";
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I updated a project from .Net Framework 4.7 to .Net Core 6.
I'm getting compilation errors saying it can't find "Microsoft.Practices.Composite.Presentation.Events"
Is this depracated? Anyone know what the new namespace is? I've been Googling and can't find it.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It looks like that was part of the Microsoft Patterns & Practices Enterprise library, which has been deprecated and no longer supported.
I don't know of any replacement library for it.
|
|
|
|
|
|
I am making a VR game and I have this script and it's getting a lot of errors. I only have one more error to diagnose, but I just can't figure out the problem. It's error code CS1001, and here is the script.
using PhotonVRManager;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon;
using TMPro;
public class NameScript : MonoBehaviour
{
public string NameVar;
public TextMeshPro NameText;
private void Update()
{
if (NameVar.Length > 12);
{
NameVar = NameVar.Substring(0, 12);
}
NameText.text = NameVar;
PhotonVRManager.SetUsername(NameVar);
}
}
|
|
|
|
|
If you search for the error number CS1001 at DuckDuckGo[^] you will find it is declaring an enum. Where that is occurring is up to you to debug and find out check out the properties of TextMeshPro (guess only)
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Since we have no idea where in that code the problem is being reported, we pretty much have to guess.
In this case, it's probably this line:
if (NameVar.Length > 12); The semicolon ends the statement, so the following code block will be executed regardless of the if condition.
If you had indented your code properly - and Visual Studio will do that for you - =that would have been pretty obvious!
You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.
We all make mistakes.
And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!
So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!
"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!
|
|
|
|
|
It might help if you would copy past the error description here. The error code alone doesn’t say much to some of us
modified 14-Nov-22 9:37am.
|
|
|
|
|
|
I have developed Console Application in .NET Compact Framework 3.5 for an embedded device.
I have a foreach loop which check for file exists. If file not found I have displayed message using MessageBox.
My message box pops up to 5 times due to use of for each loop. But at the end of 5th MessageBox display when i press Ok it gets stuck on
MessageBox.Show(p + "File Not Found...!!!!"); and does not go forward when checked in debugging mode
foreach (string p in TypeofProcess)
{
string FileToFetch1 = getFileName(p);
if (File.Exists(FileToFetch1))
{
using (StreamReader r = File.OpenText(FileToFetch1))
{
ReadAndDumpToCNC(r, 36000+i, 31000+i, 41000+i);
}
}
else
{
MessageBox.Show(p + "File Not Found...!!!!");
}
i = i + 1000;
}
|
|
|
|
|
What do you mean "does not go forward when checked in debugging mode"?
What exactly did you do, and what exactly did you find using the debugger?
And why use MessageBox in a Console app at all?
"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!
|
|
|
|