|
If the data is encoded using ISO-8859-1, then you can't use UTF8 to decode it.
You need to specify the correct encoding:
Encoding iso = Encoding.GetEncoding("ISO-8859-1");
The question remains, since you already have a string, why are you decoding it to bytes simply to encode it back to a string?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Just print / display responseXML before tinkering with it. Your "result" is single byte characters where the "right result" (and input apparently) happens to be "double-byte" characters.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi,
I tried this code:
<pre lang="C#"> if (DGVName.Rows.Count >= 1)
{
foreach (DataGridViewRow row in DGVName.Rows)
{
row.HeaderCell.Value = (row.Index + 1).ToString();
}
}
But it gives the following runtime error:
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'
|
|
|
|
|
None of the code you show uses an index: those are referenced via square brackets.
So that is the wrong code, and you need to use the debugger to find out exactly where in your code the exception is happening.
"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!
|
|
|
|
|
|
And I tried your code in my DGV and it works without problem:
private void FrmMain_Shown(object sender, EventArgs epp)
{
string strConnect = SMDBSupport.SMInstanceStorage.GetInstanceConnectionString("Testing");
using (SqlConnection con = new SqlConnection(strConnect))
{
try
{
con.Open();
using (SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM myTable", con))
{
DataTable dt = new DataTable();
da.Fill(dt);
myDataGridView.DataSource = dt;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
}
private void MyButton_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in myDataGridView.Rows)
{
row.HeaderCell.Value = (row.Index + 1).ToString();
}
}
You need to use the debugger to find out exactly which line of code is throwing the exception - because I don't think it's in the code you think it is!
"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!
|
|
|
|
|
This part
row.HeaderCell.Value = (row.Index + 1).ToString(); throws an exception.
I use generalized form in my code so I can use it as a dll file in every project.
|
|
|
|
|
Strange.
It definitely doesn't for me, so it's got to be something to do with your data and / or the DGV itself.
I'd start by breaking it down: put each "dot point" in a separate variable and see which "bit" gives a problem:
int i = row.Index;
i++;
string s = i.Tostring();
var hc = row.HeaderCell;
hc.Value = s; I'm guessing it's something to do with the HeaderCell reference, but it's worth using the debugger to see how many times it goes round that loop before it fails as well ...
"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 checked it. The error occurs in the first loop. Of course, I'm using advanced DataGridView (because of its filter capability). Maybe, I should use native DGV instead.
|
|
|
|
|
That would explain the difference between your code and mine ...
You can filter standard DGVs using a binding source - didn't we tell you that a week ago or so?
"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'm going to change them with standard DGV.
|
|
|
|
|
There was an update to advanced DataGridView. I updated it and the issue solved. The filter function also has very rapid response like Excel.
|
|
|
|
|
"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'll try to read a cwe xml file. The problem is i have not good solution read it in a good way out
That is a xml file
CWE - Downloads[]
I'll find for example ID "1004" and will read all Items behind.
When i will read value from <background_detail> i find not a way to read this out
XElement xelement = XElement.Load(@".\cwec_v4.4.xml");
var value = from cwe in xelement.Elements().Elements()
where (string)cwe.Attribute("ID") == "1004"
select cwe;
foreach (XElement xEle in value)
{
Console.WriteLine(xEle.Value);
}
var result = xelement.Elements().Elements()
.Where(x => x.Attribute("ID").Value == "1004")
.Elements().Where(x => x.Name == "Background_Details")
.Elements().Where(x => x.Name == "Background_Detail")
.Select(x => x.Value);
Have somebody experience and can help me
modified 8-Jun-21 16:20pm.
|
|
|
|
|
|
The XML document has a default namespace. You need to use that to select elements by name:
var document = XDocument.Load(@".\cwec_v4.4.xml");
var ns = document.Root.Name.Namespace;
int idToFind = 1004;
string detail = doc.Descendants(ns + "Weakness")
.Where(el => (int)el.Attribute("ID") == idToFind)
.Elements(ns + "Background_Details")
.Elements(ns + "Background_Detail")
.Select(el => el.Value)
.FirstOrDefault(); If you want to read multiple values from a single weakness, you'll want to cache the Weakness element:
XElement weakness = document.Descendants(ns + "Weakness")
.FirstOrDefault(el => (int)el.Attribute("ID") == idToFind);
if (weakness != null)
{
string description = (string)weakness.Elements(ns + "Description");
string detail = (string)weakness.Element(ns + "Background_Details").Element(ns + "Background_Detail");
...
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks a lot, it works wonderfully 
|
|
|
|
|
Hi,
I want to make a managerial app using Xamarin. Is there any free SQL Server on the cloud which I can use in Visual Studio during app development (and as a database source for my app)?
I just only need to have a small amount of storage. My clients will be less than 100.
|
|
|
|
|
There are some - normally associated with free websites - but ... would I use one? Not on your Nellie!
They are free for a reason: very limited storage, very poor or non-existent / expensive tech support, availability and speed can be very low. You really do get what you pay for!
"100 clients" doesn't necessarily mean "low storage volume", it depends on the number of clients and the space each will use. Add to that, that space is not the same as bandwidth / processing time: responses need to be timely as well as small!
And these apply to the website and the DB - so unless you really don't care for security, uptime, or space, I'd pay for it. There are good one available cheap, but use Google to find one i your country if possible - it makes support much easier and (hopefully) quicker.
"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!
|
|
|
|
|
Azure SQL Service has a trial period for use. Is it possible to put an SQLite database file in the cloud and use the cloud IP address for reading/writing database on clients' devices?
|
|
|
|
|
That is a spectacularly bad idea, and most installations of SQL Server will not allow it - to do that you have to expose the whole DB server to the internet along with all the DBs it handles, with all the security problems that opens up!
"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 recently ran into a problem where I'm running a C# program on the Windows command line and the % character is breaking things. So it's like runthisprogram.exe -variables -outputname "I am a filename 100%.mkv".
The % in the above path when passed to the application errors. They say I have to escape the % to get it to work and they are correct, but if
I am a filename 100%.mkv
is in a variable, how do I dynamically search the contents and if there is a % replace it with %%
Thanks.
|
|
|
|
|
How about
myString = myString.Replace("%", "%%");
|
|
|
|
|
|
To add to what Dave has said, that sounds like they are giving you the runaround: unless you are creating a batch or powershell file from your string then the '%' character has no special significance in either a command line to an application, or a filename. You can happily execute a C# program and hand it a single '%' as part of a file name:
using System;
namespace OneOffConsole
{
class Program
{
static void Main(string[] args)
{
foreach (string s in args)
{
Console.WriteLine(s);
}
}
}
}
Microsoft Windows [Version 10.0.19043.985]
(c) Microsoft Corporation. All rights reserved.
C:\Users\PaulG>cd "D:\Documents\AA Backed Up\My Projects\OneOffJobs\OneOffConsole\bin\Debug"
C:\Users\PaulG>D:
D:\Documents\AA Backed Up\My Projects\OneOffJobs\OneOffConsole\bin\Debug>oneoffconsole -variables -outputname "I am a filename 100%.mkv"
-variables
-outputname
I am a filename 100%.mkv
D:\Documents\AA Backed Up\My Projects\OneOffJobs\OneOffConsole\bin\Debug>dir >"x 100%.txt"
D:\Documents\AA Backed Up\My Projects\OneOffJobs\OneOffConsole\bin\Debug>type "x 100%.txt"
Volume in drive D is GriffData
Volume Serial Number is 4CA5-2F85
Directory of D:\Documents\AA Backed Up\My Projects\OneOffJobs\OneOffConsole\bin\Debug
08/06/2021 06:39 <DIR> .
08/06/2021 06:39 <DIR> ..
20/06/2019 17:39 4,079,616 itextsharp.dll
20/06/2019 17:39 3,180,097 itextsharp.xml
20/06/2019 17:39 169,984 itextsharp.xmlworker.dll
08/06/2021 06:35 4,608 OneOffConsole.exe
25/06/2019 06:47 189 OneOffConsole.exe.config
08/06/2021 06:35 19,968 OneOffConsole.pdb
08/06/2021 06:39 0 x 100%.txt
7 File(s) 7,454,462 bytes
2 Dir(s) 805,619,617,792 bytes free
D:\Documents\AA Backed Up\My Projects\OneOffJobs\OneOffConsole\bin\Debug>
But that's worrying to me: because '%' isn't a special character in Windows, or C# - but it is in SQL, and only when passing strings to a database without using parameterised queries.
And that's very dangerous as it leaves an application wide open to something called "Sql Injection" which can destroy your entire database. Applications should always use Parameterized queries instead.
When you pass strings directly, 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.
I'd suggest that you ask the developers why the '%' character is causing problems within a well-formed and quoted filename, and ask to see the code that it affects.
"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!
|
|
|
|
|
Joseline Riker wrote: The % in the above path when passed to the application errors. But you have not explained what error or where it occurs. As it stands using the % character in a filename is perfectly legal.
|
|
|
|