|
You're welcome!
"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
|
|
|
|
|
Assuming you're using WPF...
You could try my Customizable WPF MessageBox[^].
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
When you call MessageBox.Show(), you can pass the owner form as a parameter. This ensures that the message box will always be displayed above the owner form.
|
|
|
|
|
Thanks! I'll try this.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I am attempting to update a sql table based off the tables ID (which is self generated by sql when the row was first entered into the table. The below code is what I am trying to use but it will not update the row.
protected void ButtonUpdate_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=ucpdapps2;Initial Catalog=Offline_CAD;Persist Security Info=True;User ID=sa;Password=Propaganda9800!");
con.Open();
SqlCommand cmd = new SqlCommand("Update [Law_Responses] SET (Calltaker=@Calltaker,Date=@Date,City=@City,County=@County,Address=@Address) where TextBox171.text=@ID", con);
cmd.Parameters.AddWithValue("@Calltaker", DropDownList1.SelectedValue);
cmd.Parameters.AddWithValue("@Date", TextBox1.Text);
cmd.Parameters.AddWithValue("@City", DropDownList9.SelectedValue);
cmd.Parameters.AddWithValue("@County", DropDownList2.SelectedValue);
cmd.Parameters.AddWithValue("@Address", TextBox3.Text);
con.Close();
cmd.ExecuteNonQuery();
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Incident Was Updated');", true);
}
|
|
|
|
|
So little code and so many problems.
You never said what the error message was, but a quick glance shows this little gem:
con.Close();
cmd.ExecuteNonQuery();
Why would you close the connection to the database and then try to tell it to execute your query?
And then look at your query.
Update [Law_Responses] SET (Calltaker=@Calltaker, Date=@Date, City=@City, County=@County, Address=@Address) where TextBox171.text=@ID
How would your SQL server know anything at all about a TextBox in your app? It doesn't have any access to the controls in your app at all, let alone it's Text property, and it's very improbable that you have a column in your table called "Textbox171.text".
Since you're using parameters to pass values to the query already, I find it odd that you're trying, and failing, to use string concatentation to pass the value of a textbox to the query. The @ID value should also be passed as a parameter to the query.
You should also be giving your control names meaningful names and not accepting the default names in the designer. Given that this textbox is numbered 171, it seems you have a lot of work to do to make your code readable, understandable, debuggable, and supportable.
|
|
|
|
|
In addition to Dave's comments, you are also connecting to your server using the sa account. This is an unrestricted super-user account, which should never1 be used by applications. One mistake2 in your application code will lead to a hacker or disgruntled employee taking over your entire database server, and possibly your whole network.
Instead, either connect using Windows authentication, or create a specific SQL account for your application which has only the permissions required by your application.
Also, if that's your real sa password that you've just posted to a public forum, then change it immediately. And this time, pick or generate a strong password, rather than something that would likely be guessed in a few minutes.
1 The only exception would be for tools such as SQL Server Management Studio, and even then only if Windows authentication cannot be used.
2 Even without a mistake, if this is a desktop application, a user could easily decompile the code, extract the connection string, and take complete control.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I don't fully understand what functionality you want to achieve,but based on your code,you can try this:
SqlCommand cmd = new SqlCommand("Update [Law_Responses] SET (Calltaker=@Calltaker,Date=@Date,City=@City,County=@County,Address=@Address) where @Columname=@ID", con);
cmd.Parameters.AddWithValue("@Calltaker", DropDownList1.SelectedValue);
cmd.Parameters.AddWithValue("@Date", TextBox1.Text);
cmd.Parameters.AddWithValue("@City", DropDownList9.SelectedValue);
cmd.Parameters.AddWithValue("@County", DropDownList2.SelectedValue);
cmd.Parameters.AddWithValue("@Address", TextBox3.Text);
cmd.Parameters.AddWithValue("@Coumname",TextBox171.text);
con.Close();
cmd.ExecuteNonQuery();
|
|
|
|
|
Hi, I'm working in .NET 8 (not .NET Framework). Trying to programmatically create a file system link (LNK file) in C#.
I've added a reference to the Windows Script Host Object Model as detailed in many different online articles.
However, I can't seem to find the correct Using statement to import the classes in that reference.
When I say, "Using IWshRuntimeLibrary", it says it cannot resolve the type or namespace.
What must I do to import the types in the Windows Script Host Object Model reference?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
This worked fine for me in .NET 8:
using IWshRuntimeLibrary;
.
.
.
WshShell shell = new();
WshShortcut shortcut = shell.CreateShortcut(@"C:\Users\test\Desktop\Test.lnk");
shortcut.TargetPath = @"C:\Windows";
shortcut.Save();
I didn't do anything other than set the reference to the Windows Script Host Library.
|
|
|
|
|
Yes, I found that code on the web. But VS is not able to resolve IWshRuntimeLibrary even though I added the reference.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Huh.
You can try clearing the component caches. Quit VS and open the C:\Users\xxxx\AppData\Local\Microsoft\VisualStudio\version\ComponentModelCache folder and kill everything in it. Restart VS and see what happens.
If that doesn't work, there's a cache folder for Roslyn too at C:\Users\xxxx\AppData\Local\Microsoft\VisualStudio\Roslyn . Wipe that one out too.
|
|
|
|
|
<pre>I have created MSI Package using InstallShield@2014 supporting languages English - United States(1033) Chinese - Taiwan(1028)
Chinese - China(2052)
Language MST file (1033.mst, 1028.mst & 2052.mst) is embedded with MSI Package. My requirement is to update MSI Package License Agreement(EULA) for all supporting languages from any tool & Repackage MSI Package and share to end user. When end user install MSI Package he/she can see updated License Agreement(EULA) for all supporting languages.
I tried many way to update MSI Package License Agreement(EULA) but unable to find correct way to update License Agreement(EULA).
Please help me to update License Agreement(EULA) in MSI Package using C# windows application.
Thanks for any help anyone can provide.</pre>
|
|
|
|
|
You have already asked this in Quick Answers.
Don't post the same question in two places - all you will do is duplicate work and annoy people. Pick either the C# forum or the Q&A and stick with it.
Annoyed people are less likely to be helpful than happy ones...
"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 am trying to encrypt and decrypt some text using System.Security.Cryptography.Aes.[^].
Here's my Console app:
var password = "thisIsAReallllllllyLongPasswordForTesting";
var passPhrase = "E546C8DF278CD5931069B522E695D4F2";
var initVector = "HR$2pIjHR$2pIj12";
var encrypted = Cryptography.EncryptString(password, passPhrase, initVector);
Console.WriteLine("Encrypted password");
Console.WriteLine(encrypted.ToString());
string decrypted = Cryptography.DecryptString(encrypted, passPhrase, initVector);
Console.WriteLine("decrypted password");
Console.WriteLine(decrypted);
Here's my crypto class:
public static class Cryptography
{
public static string EncryptString(string plainText, string passPhrase, string initVector)
{
string encrypted = "";
using (Aes aes = Aes.Create())
{
aes.Key = Encoding.ASCII.GetBytes(passPhrase);
aes.IV = Encoding.ASCII.GetBytes(initVector);
using (var memoryStream = new MemoryStream())
{
using (var cryptoStream = new CryptoStream(memoryStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
{
using (var streamWriter = new StreamWriter(cryptoStream))
{
streamWriter.Write(plainText);
}
encrypted = Encoding.UTF8.GetString(memoryStream.ToArray());
}
}
}
return encrypted;
}
public static string DecryptString(string encryptedText, string passPhrase, string initVector)
{
string decrypted;
var inputBytes = Encoding.ASCII.GetBytes(encryptedText);
using (Aes aes = Aes.Create())
{
aes.Key = Encoding.ASCII.GetBytes(passPhrase);
aes.IV = Encoding.ASCII.GetBytes(initVector);
using (var memoryStream = new MemoryStream(inputBytes))
{
using (var cryptoStream = new CryptoStream(memoryStream, aes.CreateDecryptor(), CryptoStreamMode.Read))
{
using (var streamReader = new StreamReader(cryptoStream))
{
decrypted = streamReader.ReadToEnd();
}
}
}
}
return decrypted;
}
private static void PadToMultipleOf(ref byte[] src, int pad)
{
int len = (src.Length + pad - 1) / pad * pad;
Array.Resize(ref src, len);
}
}
I don't get any errors when encrypting, but when I decrypt I get
The input data is not a complete block.'
I thought that maybe I need to pad the input array, but when I uncomment this:
PadToMultipleOf(ref inputBytes, 16);
then I get
Padding is invalid and cannot be removed.'
Anyone know what's wrong, or maybe can point me to a working example?
Thanks
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
You need to pad the input buffer BEFORE encrypting it, to get the length of the encrypted text right.
There are a bunch of different things you can use for padding. Google something like "AES padding" to see what's acceptable to the implementation.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Thank you
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
|
Thank you
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
I replied a couple of times on the post you provided
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
The variable names and string in your example suggest you are trying to encrypt a password. That is almost always the wrong thing to do.
If you're trying to write an authentication system, you should be storing a salted hash of the users' passwords, using a unique salt per record, and multiple iterations of a cryptographically-secure one-way hash. There is no way to "decrypt" the password; instead, you use the stored salt and repeat the hashing operation on the entered password, then compare it to the stored hash.
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
If instead you're trying to store passwords or access keys for third-party systems, where you actually need to retrieve the original password, then you need to consider how you're going to store the encryption keys securely; how you're going to rotate them to minimize the impact if one is leaked; any many other complex issues. For example, you seem to be using a fixed IV for every value you encrypt, which is not secure.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have three windows form say form1 ,form2 and pin form.In form1 user have to input some values.There is save button in this page .By clicking on save button Pin form is opened in that we have enter the correct pin and by clicking on submit button form2 get opened.In Form2 the values that user entered in the form1 is displayed in the old values column.
And then the user go back to form1 and modify the values and click save button to come to form2. That modified values are displayed in new values column.
The problem is that when second time i modify the values in form1 and click save to go to form2,there i am getting old values of form1 but I want both old values and new values
|
|
|
|
|
Well, there's a problem in your secret code that you didn't show.
It's not entirely clear what you mean by "old values" and "new values", so I'm just going to say this. It sounds like you're not updating the new values in the form when Form2 returns. It seems you're like ignoring them, or you're using controls to store values instead of a data model, and/or you're binding controls to the wrong properties in your model.
In all cases, without seeing the code, it's impossible for anyone to tell you what you're doing wrong.
|
|
|
|
|
OK, that's not too bad if you handle it right.
Add a property to Form2 to take the value. In the property setter, set the old values column.
Then go to Form1 and open the PIN form using ShowDialog - that means that Form1 will be "frozen" until the user closes the PIN form.
Now create an instance of Form2 and store it in a class level variable. Handle the Form2.FormClosed event, and clear that variable to null in the handler.
Display Forms2 using the Show method.
In the Save button handler, check the variable: if it is null, do nothing.
Otherwise, use the property to set the new value(s).
Sounds complicated, but it's pretty simple when you get your head around 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!
|
|
|
|
|
Hi
I wrote the below simple code to merge two video files, it's working. But I wanna track the merging task percentage (or something that shows the progress), so I could show it using a progress bar. How to track the progress? Thanks.
textBox_taskMsg.Text = "Task is being performed.. This may take some time.";
string[] files = { textBox_Source1.Text, textBox_Source2.Text };
string output = textBox_Source1.Text + "_merged.mp4";
var conversion = await FFmpeg.Conversions.FromSnippet.Concatenate(output, files);
await conversion.Start();
textBox_taskMsg.Text = "Merge Complete.";
|
|
|
|
|