|
Displaying leading zeros on a number is usually a UI presentation thing, not a database thing.
Is the SqlLite column a numeric one or is it a text column? If you're not actually verifying this right now, after you read this, you're guessing and that's bad for troubleshooting.
Leading zeros on a value will only work if the column type is NOT numeric. Like I said, this is usually something that should be handled by the UI, not in the database.
|
|
|
|
|
@Dave Kreskowiak, Thank you very much for answering, it helped me a lot, a hug.
Where do I mark as resolved?
|
|
|
|
|
You don't have to - forums here don't have a facility for that as they are discussion based rather than "Question / Answer". We have an area for those that has a "solved" indicator: Quick Answers[^]
"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!
|
|
|
|
|
Hello,
in a .csproj file, I create a nuget package with msbuild.
All works, except that I want this package is dependent of another nuget packages.
In a nuspec file, I would write something like :
<dependencies>
<dependency id="otherNugetPackage1" version="2.0.8">
<dependency id="otherNugetPackage2" version="1.0.55">
But how could I do the same thing in the csproj file ? In which section please ?
Thank you
Chris
|
|
|
|
|
Just add a reference to the relevant NuGet packages; they will automatically be included as dependencies.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you for the answer.
I do not despair of having a solution that fits into the csproj.
Chris
|
|
|
|
|
NuGet references are already stored in the csproj file:
<ItemGroup>
<PackageReference Include="otherNugetPackage1" Version="2.0.8" />
<PackageReference Include="otherNugetPackage2" Version="1.0.55" />
</ItemGroup> What's the problem?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I want to add dependencies to nuget packages who are NOT referenced by the project.
I have missed this precision ...
|
|
|
|
|
Why? If your project doesn't reference them, then they're not dependencies of your project.
If you really want to do it, then there's no problem adding "unused" package dependencies to your project. Unless there's some specific (probably malicious) behaviour when you add such a reference, which you don't want to apply to your project?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello, I don't want to add dependencies to the project, I want to add nuget packages dependencies to the generated nuget package.
Imagine I have a third-party nuget package, containing only static datas. Only the package I try to create needs the datas, and only at runtime, not at compile time.
So : no need and no reason to add the dependant package to the project.
No ?
Chris
|
|
|
|
|
If your code needs the referenced library at runtime, then it's a dependency, and should be added as a reference. It's not going to have any adverse effect on your project, whereas missing the dependency at runtime will lead to runtime crashes.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello Colleagues, I would like to take a doubt!
Personal apologies if this is something I could google, but as you know there are a lot of articles with no opinion on the subject, I spent days reading and got nowhere.
I prefer your opinion...
I recently changed my project, disconnected from the database and saved it in a Text file, as it was just a table and nothing confidential, I solved it this way, because I think that when installing it will make the process easier, but a doubt arose in me on how to edit, and delete just one line from the file following the Contest column which is the first column,
-Question: Is it possible to edit only a certain line in a text file with more than two thousand lines?
Is it possible to delete a particular row tabem?
if it is possible: what would be the best way (Indication),
If not, what would be the best way?
database or what other way?
I have a form like in the image where I can type the numbers and save
Exemple image
my Save button and your Save TXT method
private void salvarTXT()
{
if (!string.IsNullOrWhiteSpace(txtConcurso.Text))
{
resultUltimat();
MessageBox.Show("Texto salvo com sucesso!");
}
else
{
MessageBox.Show("Insira um Resultado para salvar no arquivo Texto!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void resultUltimat()
{
const string nomeArquivo = @"C:\BoaSorte\Banco\Resultados.txt";
List<string> linhas = File.ReadLines(nomeArquivo).ToList();
if (linhas.IndexOf(txtConcurso.Text + "," + ResultTextBox[0].Text + "," + ResultTextBox[1].Text + "," + ResultTextBox[2].Text + "," + ResultTextBox[3].Text + "," + ResultTextBox[4].Text
+ "," + ResultTextBox[5].Text + "," + ResultTextBox[6].Text + "," + ResultTextBox[7].Text + "," + ResultTextBox[8].Text + "," + ResultTextBox[9].Text
+ "," + ResultTextBox[10].Text + "," + ResultTextBox[11].Text + "," + ResultTextBox[12].Text + "," + ResultTextBox[13].Text + "," + ResultTextBox[14].Text) >= 0);
else
{
linhas.Insert(0, txtConcurso.Text + "," + ResultTextBox[0].Text + "," + ResultTextBox[1].Text + "," + ResultTextBox[2].Text + "," + ResultTextBox[3].Text + "," + ResultTextBox[4].Text
+ "," + ResultTextBox[5].Text + "," + ResultTextBox[6].Text + "," + ResultTextBox[7].Text + "," + ResultTextBox[8].Text + "," + ResultTextBox[9].Text
+ "," + ResultTextBox[10].Text + "," + ResultTextBox[11].Text + "," + ResultTextBox[12].Text + "," + ResultTextBox[13].Text + "," + ResultTextBox[14].Text);
File.WriteAllLines(nomeArquivo, linhas);
}
}
my text file is being saved like this
[Exemple Image]
How I tried the edit method
private void editar()
{
try
{
using (StreamReader lendo = new StreamReader(@"C:\BoaSorte\Banco\Resultados.txt"))
{
while (lendo.Peek() != -1)
{
int linha = File.ReadAllLines(@"C:\BoaSorte\Banco\Resultados.txt").GetLength(0);
for (int i = 1; i <= linha; i++)
{
if (lendo.ReadLine() == txtConcurso.Text)
{
string caminhoArquivo = @"C:\BoaSorte\Banco\Resultados.txt";
string[] arquivo = File.ReadAllLines(caminhoArquivo);
lendo.Close();
System.IO.File.WriteAllLines(caminhoArquivo, arquivo);
}
}
}
}
}
catch (Exception)
{
}
or like this
private void ChangeUser(string currentUser, string newUser, int position)
{
string sourceFile = @"C:\BoaSorte\Banco\Resultados.txt";
string[] lines = File.ReadAllLines(sourceFile);
if (lines.Length == 0)
{
MessageBox.Show("Seu arquivo está vazio!");
return;
}
using (StreamWriter writer = new StreamWriter(sourceFile))
{
for (int i = 0; i < lines.Length; i++)
{
if (i == position && lines[i] == txtConcurso.Text)
{
writer.WriteLine(ResultTextBox[i].Text);
}
else
{
writer.WriteLine(lines[i]);
}
}
}
}
I appreciate any advice, opinion or indication
|
|
|
|
|
Text files don't have lines: they have an "end of line" symbol which is recognised by the application and interpreted as line end marker - for C# apps, that is normally "\n" or occasionally "\r\n" for some systems. They are stored by the operating as binary data that just happens to be "human readable".
That means that you can't "delete", "add", or even "change" a "Line" in a text file: to do any of that, you have to create a new file, copy everything up to the change point over, then write you new line to the output file (insert a line), skip over a line in the input file (delete a line) or do both (change a line), then copy the rest of the file over, close both files, delete the original, and rename the new one to the old file name.
This is considerably more work than using a database, and much more prone to errors! And if this is a multiuser file you are playing with, you are going to have to handle all of the fun-and-games that comes with that yourself as well, and that really isn't trivial at all!
I'd strongly suggest that you don't go down this route: it's a complicated solution to a relatively simple problem ...
"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 for your suggestion, I've been reading about SqLite, it seems like a good option, my concern would be when installing Sql Server is very complicated, I'll follow your suggestion and I'll iterate on other lighter banks.
a hug and stay with God.
|
|
|
|
|
You're welcome!
If you only need single user access to the DB, then SQLite is a very good option.
If you need multiuser access, then you need a server based DB like Sql Server or MySql - but both of those are complex to install and need planning or you will cause loads of problems you never intended to!
"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 need to be more clear about this "one line" you need to edit / delete. Where is it? Front. End. Middle? How do you identify it? Is there a key?
Yes, you can "change" text files. And, yes, text files can be used as a "backing store"; e.g. serializing and deserializing objects to XML, for example. The old "ini files" were all text files.
However, one usually "stages" the text file as a "string list" or perhaps a dictionary, updates it in there, then "serializes" it to a text file for saving ... using the users' local or "roaming" storage.
"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
|
|
|
|
|
Edilson Lemos 2021 wrote: because I think that when installing it will make the process easier
Right now you have created a solution and then you are asking questions about that.
I suspect you need to think through the problem, rephrase it to make it very clear, and then ask for ideas on how to solve that. No code, just the problem.
From the line above, to me, it suggests you might be looking to create a 'new' install of a product where data is required for the database as a new install. If so yes there are solutions for that.
|
|
|
|
|
write a c# 8 Core 7 example of InterFace and Abstract class:
namespace _07_08_2023_test
{
public interface IFace1
{
DateTime DTimeUTC { get; }
}
public interface IFace2
{
string FirstName { get; }
string LastName { get; }
}
public abstract class Abs1 : IFace1, IFace2
{
public DateTime DTimeUTC {get; } = DateTime.Now.ToUniversalTime();
public string FirstName { get; protected set; }
public string LastName { get; protected set; }
public string FullName
{
get => $"{FirstName} ... {LastName}";
}
}
public class StudentMess : Abs1
{
public StudentMess(string fname, string lname)
{
FirstName = fname;
LastName = lname;
}
}
} And, said new student says: "it compiles, and I can do this:"
private void Form1_Load(object sender, EventArgs e)
{
StudentMess smess = new StudentMess("new", "confused");
}
And, you shake your head.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Judging by your message here, and earlier posts, I guess that you're trying to figure out what problem is being solved by the new interface implementations capability being introduced in the language now. Would that be fair to say? If so, you aren't actually using that capability in your example. What am I missing here?
-- edited to add the word using
modified 9-Aug-23 6:58am.
|
|
|
|
|
Pete O'Hanlon wrote: what problem is being solved by the new interface implementations capability being introduced in the language now. Thanks, Pete
Yes, i am asking what advantages are being offered to make what, imho, is a classic pillar of modern programming a different construct. Pete O'Hanlon wrote: What am I missing here? i guess my "student mess" example did not convey the difficulty in getting a strategic sense of when to use Interface and Abstract.
bill is missing many things right now, including (too often) ability to concentrate, i apologize for my lack of thoroughness.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
So, the biggest advantage of the interface implementation is that it allows you to add features to an interface without breaking existing implementations. Imagine that you have the following interface:
public interface MyRestApi
{
string ApiName { get; set; }
int Version { get; set; }
string RequestBody { get; set; }
} Now, as an application API author, you have published this interface and your component uses it quite successfully; more importantly, you have shipped this out and 1/4 million happy customers are using your component and are supplying their own implementations of this API into your component. Let's say that you have decided that you want to upgrade your component and add a new feature to this interface; you have decided that it will support a check-sum. You don't want to upset those customers who are already using your component by breaking their build by adding a new property they have to supply. You don't want to stop those customers from having to change their code to use a version 2 of this API; which could be significant disruption. Finally, you want the customers to be able to use your upgraded capability, and adjust to supplying their own checksum implementation when they are ready. That's what this capability provides; you can upgrade the interface by supplying your own default implementation, satisfying the ability not to break things, and the consumer can upgrade the implementation if they want to later on. So, the next version of your component has this interface
public interface MyRestApi
{
string ApiName { get; set; }
int Version { get; set; }
string RequestBody { get; set; }
uint Checksum()
{
using CRC32 crc32 = new();
byte[] data = Encoding.UTF8.GetBytes(RequestBody);
byte[] hashBytes = crc32.ComputeHash(data);
return BitConverter.ToUInt32(hashBytes, 0);
}
} Now, I've just typed this code into the text window here so it may not be 100% correct, but this is one of the reasons for this capability.
modified 10-Aug-23 9:53am.
|
|
|
|
|
using C# 8 new Interface features:
public interface IExampleInterface
{
void DefaultMethod()
{
Console.WriteLine("This is the default implementation of DefaultMethod.");
}
static void StaticMethod()
{
Console.WriteLine("This is a static method in an interface.");
}
} And ... in C#9: Init-only setters; Target-typed new expressions ... in C#10: Record structs.
imho, Interface is becoming very different, and learning the strategic use of the new features much more difficult.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
I agree with your final statement. I would be interested in knowing what new devs, coming to .NET now, think of it.
|
|
|
|
|
Just to make things more confusing, a static interface member with a default implementation must be marked as virtual , otherwise you'll get a compiler error when you try to use it:
public interface IFoo
{
static void S() => Console.WriteLine("Default");
}
static void Test<T>() where T : IFoo
{
T.S();
} If you don't provide a default implementation, you have to mark it as abstract .
In order to provide its own implementation, a class has to declare the method as public , which doesn't match the interface declaration, leading to more confusion:
public interface IFoo
{
static virtual void S() => Console.WriteLine("Default");
}
public class Foo : IFoo
{
static void S() => Console.WriteLine("Overridden");
}
static void Test<T>() where T : IFoo
{
T.S();
}
Test<Foo>(); You can alleviate that by marking the interface method as public :
public interface IFoo
{
public static virtual void S() => Console.WriteLine("Default");
} But IMO, adding access modifiers to interface members goes against the "ethos" of interfaces. If I can see the interface, then I should be able to access all members of that interface, so they shouldn't need to be marked as public . And having some members protected or private just seems like nonsense!
And if that's still not confusing enough, the implementation of the static method cannot use the override modifier, even though it's required when you provide an implementation of a virtual / abstract method from a base class:
public class Foo : IFoo
{
public static override void StaticMethod() => Console.WriteLine("Overridden");
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: adding access modifiers to interface members goes against the "ethos" of interfaces. "ethos" ... right word !
i am curious which versions of future C#/.NET your thorough review of future "features" are based on ...
aside: i am still hung-up on the fact that C# inner classes within outer classes "mean nothing" ... unless, of course you want to make them private and only use/manipulate then from within their containing classes ... i am probably still in recovery from 'Self in SmallTalk, "super" in Java ... my problem !
cheers, bill
`
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|