|
So, a thesis is a rather lengthy and in-depth research paper, and you just came here asking other people to do your research for you. Do you think you should get a passing grade on the paper knowing that you can't explain at least part of it because you didn't do the research yourself?
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
You need to update your sig! Plurals imply multiple articles; there is but one link.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Whoops! Forgot to change that. Fixed!
System.ItDidntWorkException: Something didn't work as expected.
-- said no compiler, ever.
C# - How to debug code[ ^].
Seriously, go read this article.
Dave Kreskowiak
|
|
|
|
|
how to append message in sql server while we uploading any excel sheet data into database with more than 200 hundreds records
|
|
|
|
|
Member 13200944 wrote: append message in sql server while
What are you talking about? Append a "message" to what? And what does a limit of 200 records have to do with anything?
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
i am inserting more than 1oo rows in database through procedure through excel sheet. when we get
some records are already exist to our database in this case we have to append all the message in a output variable for showing that this records already exists.if u have some technique then please let me know.
|
|
|
|
|
This is a really bad habit to get into.
SQL servers are normally terrible at string handling. Having the SQL server do this doesn't scale well and can lead to memory allocation inefficiencies and other problems on the server.
Also, not every client is going to want this error message coming back and may, instead, just want an error number. This is because of localization and globalization. You can't change the language the message is generated in if it's generated on the SQL server side.
It would be better if you had the client just INSERT one record at a time and have the client side build up it's own error message strings in the local language based on the returned error code from your procedure.
It also reduces the amount of traffic coming back from the SQL server, which is better for mobile applications.
System.ItDidntWorkException: Something didn't work as expected.
-- said no compiler, ever.
C# - How to debug code[ ^].
Seriously, go read this article.
Dave Kreskowiak
|
|
|
|
|
how does the Data Adapter bridges the gap between the dataset and database?
|
|
|
|
|
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
I am new to C# (using VS 2017 CE) and have a Windows Forms App in which I would like to use MessageBoxManager.
The .DLL is present and correct in my solution, showing under References in the same manner as another .DLL which works fine.
I thought that I needed to add a "using MessageBoxManager" to my project, but when I do I get the error:
CS0246 The type or namespace "MessageBoxManager" could not be found (are you missing a using directive or an assembly reference?
If I remove the "using" line I get no error and the code runs fine, ignoring all lines such as:-
MessageBoxManager.Yes = "Yes/Oo";
MessageBoxManager.No = "No/Hindi";
MessageBoxManager.Unregister();
I suspect I am missing some elementary understanding, can anyone help me?
|
|
|
|
|
using MessageBoxManager; states that you expect that the namespace that your MessageBoxManager class is in has to be called MessageBoxManager. This cannot be the case because you cannot declare a class and namespace with the same name; .NET doesn't allow this. If you use the Object Browser View > Object Broswer, you should be able to search for MessageBoxManager. When you find it, it will tell you which namespace it is actually in. If you then look in your code, I suspect you'll find that you already have that using statement in place.
This space for rent
|
|
|
|
|
That's it, thank you for your answer.
|
|
|
|
|
Pete O'Hanlon wrote: you cannot declare a class and namespace with the same name; I respectfully suggest this is a case where C# (VS 2017, 4.7.1, Debug, error check level #4) ... still ... lets you "get away with murder:" this will compile and run:
namespace SomeClass
{
public class SomeClass
{
public int I { get; }
public string S { get; }
public SomeClass(int i, string s)
{
I = i;
S = s;
}
}
}
The user is seeing an ambiguous reference exception because he has not dot-qualified his call. imho, the C# compiler should never allow this ! I;m surprised ReSharper doesn't red-line this.
Happy New Year !
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it.» Claude Levi-Strauss (Tristes Tropiques, 1955)
modified 29-Dec-17 20:58pm.
|
|
|
|
|
See my explanation of why your code does not work in my response to Pete O'Hanlon on this thread. I think you may be surprised by what you learn.
A NameSpace with a Class (or anything else) with the same name inside it is a bad practice that will cause problems.
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
Hi,
HTML string as a JSON output.
Facing issue with the HTML string: String has HTML tags and text.
Actual string - There are HTML tags and text. In <span> tag there is id with double quotes, and there is text "since the 1500s" which also has double quotes.
<p>Lorem Ipsum is simply dummy text of the printing <span id="#" ids="#" display="inline"></span> and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever "since the 1500s".<br></p>
Expected string - All double quotes in the HTML tags should be converted into single quote but the text quotes should be as it is.
"<p>Lorem Ipsum is simply dummy text of the printing <span id='#' ids='#' display='inline'></span> and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever \"since the 1500s\".</p>"
|
|
|
|
|
Try a (complicated) regex:
public static Regex regex = new Regex(
"\"+(?=[^<]*?>)",
RegexOptions.Multiline
| RegexOptions.Singleline
| RegexOptions.CultureInvariant
| RegexOptions.Compiled
);
...
string result = regex.Replace(InputText,"'"); Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions. It helped me create and test that, then generated the C# code automatically.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hey Guys,
Hope you guys are doing great! I have one question kind of stuck there. In the JSON File, I would like to extract the data from the node. Say like I wanted to extract the book node or value which is within goods node. Here is my JSON file.
{"store": [
{
"name": "Sunshine Department Store",
"address": "Wangfujing Street",
"goods": {
"book": [
{
"category": "Reference",
"title": "Sayings of the Century",
"author": "Nigel Rees",
"price": 8.88
},
{
"category": "Fiction",
"title": "Sword of Honour",
"author": "Evelyn Waugh",
"price": 12.66
}
],
"bicycle": {
"type": "GIANT OCR2600",
"color": "White",
"price": 276
}
}
}
]
}
Here is my code
private string ParseBookNode(JObject bookJSONFile)
{
JArray bookJson = null;
string bookFarmNode = null;
if (bookJSONFile != null && bookJSONFile["store"] != null)
{
bookJson = (JArray)bookJSONFile["store"];
bookFarmNode = bookJson[0].ToString();
if (bookJSONFile["book"] != null)
{
bookJson = (JArray)bookJSONFile["book"];
bookFarmNode = bookJson[0].ToString();
}
}
else
{
throw new Exception("Book node not found.");
}
return bookFarmNode;
}
How I can able to extract data along this lines??
if (bookJSONFile["book"] != null)
{
bookJson = (JArray)bookJSONFile["book"];
bookFarmNode = bookJson[0].ToString();
}
|
|
|
|
|
You will find that life will be much, much easier if you write container classes for these JSON objects and deserialize directly into instances of those objects. It'll also help you handle these items as strongly-typed objects in your code. I can tell you've done a bit of XML handling in the past, and it's just a different way of handling it.
public abstract class Product
{
public decimal Price { get; set; }
}
public class Book : Product
{
public string Category { get; set; }
public string Title { get; set; }
public string Author { get; set; }
}
public class Bicycle : Product
{
public string Type { get; set; }
public string Color { get; set; }
}
public class Store
{
public string Name { get; set; }
public string Address { get; set; }
public Dictionary<string,List<Product>> Goods { get; set; }
public Store()
{
Goods = new Dictionary<string,List<Product>>();
}
}
There are a couple of ways to handle the "goods" collection, but this is the easiest and should work with JSON.Net out of the box. How you obtain your object can vary a little, but parsing it directly from the original stream is preferable just for efficiency:
public Store GetStoreInventory(string fileName)
{
using(var jsonFile = new FileStream(fileName))
{
using(var reader = new StreamReader(jsonFile))
{
return JsonConvert.DeserializeObject<Store>(reader.ReadToEnd());
}
}
}
From here you can handle the data just like you would any normal .NET CLR type, i.e.
var store = GetStoreInventory(FILEPATH);
var firstBook = store.Goods["book"].FirstOrDefault();
The only "gotcha" is that the JSON.NET deserialize does not play nicely with interfaces, so use abstract classes instead (hence Product rather than IProduct).
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Hi All,
I have just started to self learn C#, and have written my first basic application.
It is pretty simple,it has 8 text boxes that accept numerical values, which it then does some calculations on and displays 3 textbox outputs.
I worked out the calculations using Excel then translated that into C# and it all works ! as long as no one puts the wrong numbers in !
What I am trying to achieve is to validate four types of inputs:
One set of text boxes can accept whole numbers and no letters from 1 to 1000
One set of text boxes can accept whole numbers and no letters from 1 to 100
On these two types of textboxes, I have this code:
private void totalsize_TextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(totalsize.Text, "[^0-9]"))
{
MessageBox.Show("Please enter only full numbers i.e. 70 NOT 65.5");
totalsize.Text = totalsize.Text.Remove(totalsize.Text.Length - 1);
totalsize.Focus();
}
}
From what I understand the regex is basically checking that the first character is not non numerical, so it sort of does one part of what I needed it to do.
I then have another input that I want to be able to validate: numbers only again, but only allow a single number with a single decimal point i.e. 7.2 3.6 but not 7.22222 or 70 so anything from 1 to 9 including a single decimal point.
private void nicstrength_TextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(nicstrength.Text, "insert jibberish here"))
{
MessageBox.Show("Please enter only numbers.");
nicstrength.Text = nicstrength.Text.Remove(nicstrength.Text.Length - 1);
nicstrength.Focus();
}
}
The last input I want to validate will be again numbers only but from 0.n to 2.n , so 0.6 or .6 - 1.2 or 2 (2 or above will probably not ever get entered)
private void finalnicstrength_TextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(finalnicstrength.Text, @"^[1-9]\d*(\.\d+)?$"))
{
MessageBox.Show("Please enter only numbers.");
finalnicstrength.Text = finalnicstrength.Text.Remove(finalnicstrength.Text.Length - 1);
finalnicstrength.Focus();
}
}
I have tried zillions of combinations found on the net, plus I've used a couple of regex generators (frustratingly, some say a regex works and some say it doesn't - but none work when I put them into my code !)
I've learnt that I either need to put an @ in front of it, or use double \\ or whatever for C# to know what it is, but i'm just really struggling with this.
I am dyslexic (not looking for sympathy) so looking at regex makes my head explode !
Please can someone help me with the last two types at the very least, I know the top two are not 100% correct, but they at least stop letters and decimal points being entered.
Many thanks for reading, and even more for helping me !
Damian
|
|
|
|
|
Basically, don't use a regex!
The simplest solution is this:
int value;
if (!(int.TryParse(myTextBox.Text, out value) && value >= 1 && value <= 100))
{
MessageBox.Show("Please enter a number between 1 and 100");
...
return;
} It's clearer, it's much simpler to maintain, and it gives you the value as a number for when you need it later.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This also has the benefit of being faster than a regex. Try to save regex for things where absolutely nothing else will do like dealing with string lookups in long documents and protocol parsing; regex are not as fast as you might think.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Nathan Minier wrote: regex are not as fast as you might think
I know! Counting Lines in a String[^]
It compares the different ways to do it: brute force, regex, Linq, ... interesting results.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I've done a few tests for a BSON parser that I've been working on, and found that regex is literally 100x slower than a String.Split implementation with count checks (for my use case anyway). I was floored.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
It surprised me that both Linq and Regex were so slow: Split is not nice either due to the number of object allocations you need but I was expecting that - allocation is always a time consuming operation.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|