Jump to content

madknight3

Member
  • Posts

    1,786
  • Joined

  • Last visited

Reputation Activity

  1. Agree
    madknight3 got a reaction from mrchow19910319 in WTF is up with School These Days   
    You know that Java can do more than just build applets, right?
    You know that a lot of companies use Java, right?
    You know that no language is the best choice for every situation, right?
     
    It's unfortunate that you used the wrong language, or potentially just the wrong project type, for the job but that's hardly a reason to criticise the language from being taught in schools. With that said, many schools are changing, or have already changed, their intro courses away from Java. A lot are choosing Python while some are going with other languages. So there are valid reasons to move away from Java, according to some people, however, yours just isn't one of them.
     
     
  2. Like
    madknight3 got a reaction from Goldman in c# mapping parameters to class instance properties   
    While it's not exactly what you're asking for, there are tools that can generate the constructor code for you so you don't have to write it out yourself (example). You can also create your own generator.
     
    More in line with your question, I don't know of an existing solution, but you might be able to create your own solution using reflection. Here are some resources that may or may not help with that. At the very least it should give you an idea of the types of things you would want to search for.
    http://stackoverflow.com/questions/214086/how-can-you-get-the-names-of-method-parameters
    http://stackoverflow.com/questions/737151/how-to-get-the-list-of-properties-of-a-class
    http://stackoverflow.com/questions/619767/set-object-property-using-reflection
  3. Agree
    madknight3 got a reaction from Seuntjie in How to get date from database and display in textbox as Date/Month/Year format?(ASP/C#)   
    I think you should just be able to cast from the reader and not have to go through a string conversion at all.
    // Cast instead of using ToString DateTime sdate = (DateTime) reader2["Date"]; // Then format it as desired. Example: string formattedDate = sdate.ToString("dd-MM-yyyy");  
  4. Agree
    madknight3 got a reaction from jslowik in How to get date from database and display in textbox as Date/Month/Year format?(ASP/C#)   
    Note that ToShortDateString is culture specific so it won't format the same for everyone. For example, ToShortDateString uses a "yyyy-MM-dd" format for me.
    DateTime.Now.ToString("yyyy-MM-dd") == DateTime.Now.ToShortDateString() // true for me  
  5. Agree
    madknight3 reacted to jslowik in How to get date from database and display in textbox as Date/Month/Year format?(ASP/C#)   
    Excellent point. It didn't matter for my purposes, but I could see this being an issue in certain situations and definitely worth a mention.
  6. Like
    madknight3 got a reaction from LegionOfOne in Need help finding the error in this SQL statement   
    It's hard to know exactly what's wrong without seeing your data. The best way to know for sure is for you to post some test data and the correct order you want the data to be displayed. I'll give a couple guesses below though.
     
    It could be that what you really want is to ORDER BY SenderID and not UserID. Example.
    Given this data SenderID, Subject, UserID ------------------------- 1, "Subject 1", Scott 2, "Subject 2", Admin 3, "Subject 3", Betty Using ORDER BY UserID will sort it like this 2, "Subject 2", Admin 3, "Subject 3", Betty 1, "Subject 1", Scott Since you aren't selecting UserID it could be that it just looks out of order. 2, "Subject 2" 3, "Subject 3" 1, "Subject 1" Using ORDER BY SenderID will return this 1, "Subject 1", Scott 2, "Subject 2", Admin 3, "Subject 3", Betty Or it could be that because you're using a string and not a number for your UserID column, it's sorting lexicographically and it's not doing what you want. Example.
    Say you have this data UserId ------ Admin1 Admin2 Admin100 You might think "ORDER BY UserID" will result in the above order. However, it will actually result in this order. Admin1 Admin100 Admin2 Because the database doesn't look at the numbers at the end of the UserID as an integer.  
  7. Informative
    madknight3 got a reaction from Shammikit in How to get date from database and display in textbox as Date/Month/Year format?(ASP/C#)   
    I think you should just be able to cast from the reader and not have to go through a string conversion at all.
    // Cast instead of using ToString DateTime sdate = (DateTime) reader2["Date"]; // Then format it as desired. Example: string formattedDate = sdate.ToString("dd-MM-yyyy");  
  8. Like
    madknight3 got a reaction from ChuckMaurice in How to count the number of records in sql server using C#   
    Just in case OP gets confused, for their current query where they are getting the count, and for any query that returns a single value, ExecuteScalar is the best option. So they are correct in that regard. It's overkill to use anything else.
     
    Also, note that there are pros and cons to the different readers (performance, memory usage, convenience, etc). In some cases, you'll want to use SqlCommand/SqlDataReader over SqlDataAdapter and vice versa.
     
    Here are some references
    StackOverflow: What is the difference between ExecuteScalar, ExecuteReader and ExecuteNonQuery?
    StackOverflow: When to use ExecuteScalar,ExecuteReader,ExecuteNonQuery?
    StackOverflow: SqlCommand or SqlDataAdapter?
    StackOverflow: SqlDataAdapter vs SqlDataReader
  9. Informative
    madknight3 got a reaction from Shammikit in How to count the number of records in sql server using C#   
    You use parameter @xy in your query and then add parameter @x to the command.
    SqlCommand check_User_Name = new SqlCommand("SELECT COUNT(*) FROM [Employees] WHERE ([emp_ID] = @xy)", cn); check_User_Name.Parameters.AddWithValue("@x", textBox1.Text);  
    You also mention this but use the greater than operator instead of the equals operator
    if (UserExist > 0)  
  10. Like
    madknight3 got a reaction from Shammikit in How to count the number of records in sql server using C#   
    Just in case OP gets confused, for their current query where they are getting the count, and for any query that returns a single value, ExecuteScalar is the best option. So they are correct in that regard. It's overkill to use anything else.
     
    Also, note that there are pros and cons to the different readers (performance, memory usage, convenience, etc). In some cases, you'll want to use SqlCommand/SqlDataReader over SqlDataAdapter and vice versa.
     
    Here are some references
    StackOverflow: What is the difference between ExecuteScalar, ExecuteReader and ExecuteNonQuery?
    StackOverflow: When to use ExecuteScalar,ExecuteReader,ExecuteNonQuery?
    StackOverflow: SqlCommand or SqlDataAdapter?
    StackOverflow: SqlDataAdapter vs SqlDataReader
  11. Like
    madknight3 got a reaction from ChuckMaurice in problem occurred when updating sql server table records using C#   
    In C#, the backslash (\) is used to allow characters that have a special meaning to be a part of the string. Here's some example of escape sequences.
     
    You either need to escape your backslash (\\)
    SqlConnection cn = new SqlConnection("Data Source=Dell-PC\\SQLEXPRESS;Initial Catalog=employee_db;Integrated Security=True"); Or use a string literal (@ sign in front of string) which treats each character as it's written and doesn't require the use of escape sequences.
    SqlConnection cn = new SqlConnection(@"Data Source=Dell-PC\SQLEXPRESS;Initial Catalog=employee_db;Integrated Security=True"); Side note for string literals, double quotes are added into it like so
    var s = @"\this is a ""test"" string\"; var s2 = "\\this is a \"test\" string\\"; // Both of the above store // \this is a "test" string\ Also, note that you're missing a parameter for @npid
    SqlCommand cmd = new SqlCommand("UPDATE Posts SET description=@des WHERE id =@npid"); cmd.Parameters.AddWithValue("@des",textBox1.Text);  
  12. Like
    madknight3 got a reaction from ChuckMaurice in How to count the number of records in sql server using C#   
    You use parameter @xy in your query and then add parameter @x to the command.
    SqlCommand check_User_Name = new SqlCommand("SELECT COUNT(*) FROM [Employees] WHERE ([emp_ID] = @xy)", cn); check_User_Name.Parameters.AddWithValue("@x", textBox1.Text);  
    You also mention this but use the greater than operator instead of the equals operator
    if (UserExist > 0)  
  13. Like
    madknight3 reacted to Mira Yurizaki in How should I learn python   
    That book reminds me of this:

  14. Like
    madknight3 got a reaction from ChuckMaurice in Syntax error near 'text'   
    Sounds like you have an error with your SQL statement. Make sure the string that's created is a valid query. You should be able to set a breakpoint and view the query string after it's assembled. 
     
    I also recommend parameterizing your queries to protect against SQL Injection and to have to worry less about the format of your values (don't have to manually deal with quotes and stuff).
    SqlCommand sc=new SqlCommand("insert into TabelaKlienci values(@Column1,@Column2,@Column3,@Column4,@Column5,@Column6)",con); // If you want to explicitly declare the data type sc.Parameters.Add("@Column1", SqlDbType.VarChar).Value = variableForColumn1; sc.Parameters.Add("@Column2", SqlDbType.Int).Value = variableForColumn2; //etc // or if you don't sc.Parameters.AddWithValue("@Column1", variableForColumn1); sc.Parameters.AddWithValue("@Column2", variableForColumn2); // etc // You can name the parameters anything you like, I just used @Column1, etc because I don't know what your columns are named  
    They are optional, although I think it's a better practice to use them.
  15. Like
    madknight3 got a reaction from Mr_KoKa in Syntax error near 'text'   
    Sounds like you have an error with your SQL statement. Make sure the string that's created is a valid query. You should be able to set a breakpoint and view the query string after it's assembled. 
     
    I also recommend parameterizing your queries to protect against SQL Injection and to have to worry less about the format of your values (don't have to manually deal with quotes and stuff).
    SqlCommand sc=new SqlCommand("insert into TabelaKlienci values(@Column1,@Column2,@Column3,@Column4,@Column5,@Column6)",con); // If you want to explicitly declare the data type sc.Parameters.Add("@Column1", SqlDbType.VarChar).Value = variableForColumn1; sc.Parameters.Add("@Column2", SqlDbType.Int).Value = variableForColumn2; //etc // or if you don't sc.Parameters.AddWithValue("@Column1", variableForColumn1); sc.Parameters.AddWithValue("@Column2", variableForColumn2); // etc // You can name the parameters anything you like, I just used @Column1, etc because I don't know what your columns are named  
    They are optional, although I think it's a better practice to use them.
  16. Like
    madknight3 got a reaction from AlTech in Error with number output in C#?   
    I don't think this code will do what you want it to do
    multiTimeStopwatch.Start(); //Start the threads and make the benchmarking happen! pyThread.Start(); trigThread.Start(); multiTimeStopwatch.Stop(); That's just timing how long it takes to start up the threads. It doesn't take into account how long the threads run for. You probably want something more like these answers describe - StackOverflow: How to wait for thread to finish with .NET?
     
    edit (to answer your original question): So regarding the printing issue, I think it's because multiTimeStopwatch.ElapsedMilliseconds is zero because there's not enough precision to measure something that fast. Which means you're dividing by zero later. Here's some code to explain.
    class Program { static void Main(string[] args) { double multiTime = 0; double x = 1 / multiTime; Console.WriteLine(x); // prints weird character // If you were using integers it would throw an exception. // However double has the notion of Infinity and NaN so it doesn't throw an exception bool b = double.IsInfinity(x); // is true Console.WriteLine(b); } } Side note, some programs may properly print out an infinity character. Like LINQPad did when I tested with that.

     
    Another side note, if ElapsedMilliseconds isn't enough in the future you may be able to get a value from ElapsedTicks - StackOverflow: How do you convert Stopwatch ticks to nanoseconds, milliseconds and seconds? (I've never looked into the accuracy of this though)
  17. Like
    madknight3 reacted to -iSynthesis in Changing code style in Jetbrains Webstorm   
    You honestly saved my life, thought i had to abandon this program already^^
  18. Like
    madknight3 got a reaction from Shammikit in How to select the most recently inserted record from table of sql server database   
    That's fine. I just wanted to give the OP my take on the answer and show the difference between the MySql and Sql Server limit syntax.
    In many cases this can work fine and it's probably fine for the OPs use case, although they doesn't really say what that is. Still, I don't think it's a better practice than using a DateTime column which was created for this very purpose (which the OP states they have in the table).
     
    Also, as far as I know there's no guarantee that auto increment will keep the proper order in scenarios where the database receives multiple inserts at around the same time. This might not be an issue for the OPs use case, but it's worth mentioning.
  19. Like
    madknight3 got a reaction from vorticalbox in How to select the most recently inserted record from table of sql server database   
    That's fine. I just wanted to give the OP my take on the answer and show the difference between the MySql and Sql Server limit syntax.
    In many cases this can work fine and it's probably fine for the OPs use case, although they doesn't really say what that is. Still, I don't think it's a better practice than using a DateTime column which was created for this very purpose (which the OP states they have in the table).
     
    Also, as far as I know there's no guarantee that auto increment will keep the proper order in scenarios where the database receives multiple inserts at around the same time. This might not be an issue for the OPs use case, but it's worth mentioning.
  20. Agree
    madknight3 got a reaction from whiteGloveReview in Learning C & C++   
    Sure, but there's nothing wrong with learning C or C++ for your first language either.
    It's unclear if you're going to be learning one language or two for this course (the last part of this sentence implies one language but the title suggests two). C and C++ are two separate programming languages. Unless the course requires learning both C and C++, then you'll just want to focus on just one of them.
     
    Some people view C++ as C with some extra features and will recommend learning C first and then C++. This approach tends to cause people to learn C++ in a C style (although it depends on the learning material you're using). In my experience, most people these days consider that an outdated view of C++ and recommend treating them as completely different languages and to approach learning them differently. Ultimately we can't know how your course is expecting you to learn these languages (or if it even matters).
     
    Some general resources:
    StackOverflow: The Definitive C Book Guide and List
    StackOverflow: The Definitive C++ Book Guide and List
    LearnProgramming Subreddit: C++ FAQ
    Pluralsight
    Lynda
  21. Agree
    madknight3 reacted to manikyath in How to hack chromebook?   
    it's not your own device, you have no right to do this.
    /thread.
  22. Funny
    madknight3 reacted to Dat Guy in Which language for back-end, front-end and logic   
    I'm not sure if using Cloudflare is actually a great idea.
  23. Agree
    madknight3 got a reaction from straight_stewie in I'm confused about the commenting part in python   
    Keep in mind that school assignment requirements don't always match industry best practices. In industry, it's a common practice to try and make your code as understandable as possible without comments. So in many cases, adding comments can often be unnecessary.
     
    However, in a school setting, choosing to leave them out may cause you to lose marks on an assignment if they are an explicit requirement. You might be able to argue to your professor that your code is clear and doesn't need comments, however I wouldn't risk it. That doesn't necessarily mean you need to comment every line of code, but don't remove them all either. A comment per "section", like straight_stewie said, is a good general approach. Adjust as you feel it's necessary.
     
    You can always ask your professor for clarification on what they consider "useful" vs "redundant/unnecessary". What you have may be similar to what they are looking for. Maybe not. Ultimately we can't know what your professor wants.
     
    There's a lot of tips on when it's good/bad to write comments in your code (ex: Google things like "when to comment code" and browse the results) but the advice won't necessarily apply to school assignments (or may just include advice that's too advanced for you right now). When in doubt, follow the professors requirements above all else, and ask them for help/clarification if necessary.
  24. Like
    madknight3 got a reaction from Claryn in Languages/frameworks to get valuable experience while studying   
    It sounds like C++ is where you want to be. You're considering game development, which is an area where C++ plays a big role, and applying for an internship that you think uses C++, so it sounds like it's worth spending some time on that. Whether game development is something you end up doing or not, C++ isn't a bad language to be familiar with anyway.
     
  25. Agree
    madknight3 got a reaction from mackncheesiest in Books for Java Beginners   
    Check out Must-reads for Java Developers: From Beginner to Professional. Couple notes
    Head First Java is a little dated now, covering Java 5. Which means it doesn't have the new language features from Java 6, 7 and 8 which was the latest release. That isn't stopping people from continuing to recommend it though (ex 1, 2). They just recommend using other material to cover the newer features. Java, A beginners Guide has been updated to a 6th edition and does include the new features.  
    Just keep in mind that you're going to find people for and against any book, even good ones. If the large majority of reviews are positive, it's probably worth considering.
     
    Also, remember that no book can cover everything and even good books will leave stuff out or can have weak areas. Learn from multiple sources and always be open to exploring new ways to do things.
×