|
Going through a C# book (Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer) and am having a mysterious problem with one of the exercises. The program has two forms, the main form having text boxes and buttons, click a button and the other form comes up with a List View where you select an item, click OK and the main form's text box has that item in it. My problem is that the List View form does not have any items highlighted by default or remember what item was highlighted before. The code looks nearly identical to the book code that works and I can't find a difference that would cause this. My main form code code:
code:
|
# ¿ Jun 28, 2012 21:00 |
|
|
# ¿ May 22, 2024 16:42 |
|
Ithaqua posted:Throw that book in the garbage, it's teaching you horrible practices. Indeed, I just came off a two week .NET class and seeing some of the things in this book the way it's written out is a bit surprising. One of the exercises is to "Make a program that displays the days of the week for your next 10 birthdays in a list box." I couldn't think of how to do this without loops which wouldn't be introduced until a later lesson. I came up with code:
code:
|
# ¿ Jun 28, 2012 22:35 |
|
I'm 2 months in to my first programming job and have no idea what I'm doing. My training project last month involved database queries. My coworker gave me a good start by giving me a SQLConnector class that has a method that executes SQL queries from strings. Using that class I was able to create a SQLFiller class that populates ComboBoxes based on whats in the column, have those Combo Box choices insterted as part of SQL strings for the DataGridViews that display the results of the query. I also added a button that exports the results as a .csv or .txt. Now I'm trying to understand entity framework as I've been hearing that that's the way things should be done from now on. I've tried reading the book I got from our big training session and didn't understand much past add new ADO.NET Entity Data Model. I'm trying to build a training project similar to the last one that will do more than display data, but actually take data from a .csv and update the table. Of course right now I just want to be able to push a button and see something and build from there. Considering I'm pretty much learning via plagiarism, where should I look for help with getting better at these programming problems? Also, how in over my head am I considering I spend most of the day reading programming books and not understanding anything and not understanding the SQL queries I have to write based on vague requirements? I don't want to give up on this job but I think I got to make a bit more progress soon before it becomes apparent I don't really do anything here.
|
# ¿ Jul 27, 2012 01:39 |
|
Ithaqua posted:Is there anything specific you're having trouble grasping? Right now, you're just saying "I'm trying to learn this stuff and I can't, help!", which we're not going to be able to do anything about. Indeed, I needed to vent a bit. I did not have a productive week. I managed to do the schools tutorial last Friday and then make *something* that reached out and touched my dev database, now I just have to learn LINQ better and make it return what I want. That's going on the back burner now because I just got a work order similar to my prior project. In the interest of time I'm falling back to SQL queries passed as strings and combo boxes for variables, this time using date time dialogs to filter out a range of data and providing aggregate information from there. I'm building this from my prior project so it shouldn't be too hard and hope to have something I can show my boss in a couple days. Wish me luck.
|
# ¿ Jul 30, 2012 19:01 |
|
Ithaqua posted:Please tell me you're using parameterized queries, at least. Well you learn something new every day.... While the examples I read on the web focused on text field entries, is there a danger in using combo boxes? It seems like a good habit to get into anyways. OK as before when I was using StringBuilder.AppendFormat("SELECT * FROM Foo WHERE Bar = {0}", ComboBox.SelectedItem) I changed it to use StringBuilder.Append("SELECT * FROM Foo WHERE Bar = @Something"); SQLCommand.Parameters.AddWithValue("@something", ComboBox.SelectedItem); Is there a similar thing I need to worry about when I get to LINQ queries? query = from row in query where row["Something"].ToString() == cmbSomething.SelectedItem.ToString() select row;
|
# ¿ Jul 30, 2012 21:13 |
|
Ithaqua posted:The fact that more senior developers let you get that code into a production codebase is a very bad sign. Is it better than an outsourced Indian at least? Hell if I know...
|
# ¿ Jul 30, 2012 22:02 |
|
Last time I was struggling with stretching SQL strings as far as I could. I have another project that I got till the end of the month to figure out although I would love to get it done sooner. Before someone would get data in the mail, write it on an excel spreadsheet, send it to me. I would convert that to a .csv and run SQL to import that on the database. The goal is to write a program where he can write the data in there and have it write to the database. So how do I update the database? I tried a SQL string again and it would not work so I figured now was a good time to try entity framework again. I went through the Data Source Configuration Wizard to get my Model1.edmx. I create the object I want to become a new row on the database by matching the properties with the text boxes. code:
https://www.youtube.com/watch?v=EMvWojwKIrk She has code:
code:
Why does she use var instead of the Entities class as the object type like the Wrox books demonstrate? I tried var and got the same error. Anyways research on that error suggests the problem may be lack of a primary key in the table. A more senior team member is going to help me with the key issue tomorrow but in the meantime, what other pieces to this puzzle am I missing? ***update*** Solved the problem by following advice at http://stackoverflow.com/questions/1589166/it-has-a-definingquery-but-no-insertfunction-element-err Crazy Mike fucked around with this message at 20:50 on Aug 22, 2012 |
# ¿ Aug 22, 2012 01:40 |
|
PROBLEM: Someone's birthday is in a datagridview cell in yyyy/mm/dd format. I want to get a copy of it in mm/dd/yyyy format in a masked text box in case it's wrong and needs to be edited. After all, I'm pretty sure his birthday isn't 19/81/1028. SOLUTION: code:
|
# ¿ Aug 28, 2012 20:01 |
|
Another problem with my queries I'm trying to solve. I am getting different results when I try to get a LINQ version of my SQL string involving a left outer join, multiple join conditions, and including null values... something similar tocode:
code:
|
# ¿ Sep 6, 2012 21:21 |
|
Okita posted:You probably already figured this out by now, but why not wrap this SQL up in a database view? You can then import the view into your project .dbml and use it as if it were a LINQ table. Actually I stuck with the SQL query and put my other attempt in a method that never gets called to be fixed later. I actually don't understand what the recommendation you're making is. (I am probably one of the most junior programmers out there.) I've spent the past month working on this program and recently got significant suggestions for improvement in a code review. I've been working on most of them and hope the results are more satisfactory at the next review. I'm starting to wonder if this will get into production this year. It was supposed to be done last month.
|
# ¿ Sep 19, 2012 20:52 |
|
Okita posted:view advice Thanks for the tip. I tried it out and got it to display in my DataGridView. I am probably not going to use it in the final product because using a view or the old entity framework display loses the automatic sorting by clicking a column header. Which leads to another thing I'm trying to figure out... how do I make that triangle in the column header indicating the sort direction disappear?
|
# ¿ Sep 20, 2012 01:06 |
|
I've been looking at a method that validates e-mail addresses today and wondering how much of it needs to be cleaned up.code:
Second, shouldn't it be if (AtSignIndex < 1) due to zero indexing? Third, I never used/don't know regex, but shouldn't they be able to check for these two issues? Doesn't it already check that the first character isn't @? After reading http://www.regular-expressions.info/email.html it mentions you can exclude two dot matches by replacing [A-Z0-9.-]+\. with (?:[A-Z0-9-]+\.)+ The website also mentions successive dots aren't allowed before the @ either, although that is something not usually tested for. If we don't worry about that, can we make that change to the regex to allow for not matching two dots and get rid of everything before it?
|
# ¿ Sep 21, 2012 01:28 |
|
ninjeff posted:Fix up those PascalCase parameter and local variable names while you're at it! The big long term project we need to do is taking our main application written in Power Builder and rewriting it in .NET. The current naming convention is "<scope><type>_Name", so imagine me removing li_ and ls_ from those local int and string variables just for forums readability. We need to look into changing that as we move into .NET. When that time comes I'm going to build a comparison chart of what we have to what MSDN recommends, but it would help if I could articulate why we shouldn't do things that way and switch to what MSDN recommends. The small project this method came from was built by a former employee as a learning .NET exercise. My learning .NET exercise is trying to understand how it works/should work, and hopefully actually making it work.
|
# ¿ Sep 21, 2012 03:06 |
|
I had my second code review for my small project that's taking a long time. The biggest thing I need to improve is learning what happens if multiple users are running the program and try to update the database? Are there appropriate locks and constraints to prevent problems? Is there a difference in that behavior in the SqlConnection/SqlTransaction objects and the Entity Framework objects in that regard? We also got into a discussion on how I should think about moving much of that to the database as a stored procedure. I'm going to spend some time reading about SQL programming so I can hopefully fake an intelligent answer when asked these questions and then decide what I'm going to do about it. Minor things to improve were adding a control that only programmers can see to choose the database instead of commenting/uncommenting code as necessary, changing the blink property on the error providers, and figuring out how to use one entity framework model for multiple databases by changing the connection string.
|
# ¿ Oct 5, 2012 22:35 |
|
I'm working on a program that reads a text file and determines if each line meets certain criteria. I got something that works, but am wondering if some assumptions I made are not good practices. The main one I'm concerned with is if the file is a text file?code:
I'm also not too happy that I couldn't figure out how to use a Background Worker to update the text boxes while a large file was being processed and used Application.DoEvents(); in the loop instead. I've got about one day left for minor improvements and it works now, so I'm wondering if I should worry about these types of things or turn each validation check into a separate method so the foreach loop isn't so big. Since seven of those checks involved is this position in the string the delimiter character?, I spent today making that its own method along with making sure each validation does what its supposed to.
|
# ¿ Oct 24, 2012 01:32 |
|
My screw up at work today... I wrote a program that sends a couple SQL queries on a timer. The first query calculates a number, the second query updates a table row with a message about what the number is and when it was calculated. I use a Timer that ticks every second to show a clock on the form, and decides whether to run the query based off DateTimePicker and ComboBox values. When I switched to the production server, the times did not match. I was using DateTime.Now to determine when to run the queries and select GETDATE()to determine when the calculation was performed. The two clocks were off by a minute. My boss would prefer basing time off the server instead of DateTime.Now. So lets think of possible solutions... 1.) I know the clock is off by a minute so I will offset the program to run a minute later to compensate. This really doesn't solve anything though... 2.) I can just change the SQL string for the second query to have the time variable from the local machine instead of the server. This goes against the preference that we use the server time instead of the local machine time. 3.) My timer will query select GETDATE() at every tick to ensure that the time is synchronized. This results in a lot of unnecessary queries run, something I'm pretty sure we should avoid. 4.) We run the program off the server instead of the local machine so that DateTime.Now and select GETDATE() are the same. Is this the right answer or is there a better way to solve this problem?
|
# ¿ Nov 29, 2012 02:25 |
|
I've got another problem I'm trying to solve. I'm working on a form. In the form's load event is a call to the database setting the ownership of that form to the user. In the form's closed event is a call to the database setting the ownership to an empty string. If the ownership of the form is not an empty string during the load event it means someone else owns it. A MessageBox asks if you want to override the setting and force the window open. If you click yes it updates the ownership, if you click no it closes the form. The problem is the ownership of the form shouldn't be reset to an empty string when you click no on the MessageBox. Object sender and FormClosedEventArgs e are the same for both calls, so how do I differentiate between them to make the right choice in the event?
|
# ¿ Dec 14, 2012 19:16 |
|
gariig posted:This sounds like a logic problem to me. Are you saying in the Form.Load you are checking to see if someone "holds" this piece of data like an Order. If there is someone else viewing this Order the second person can either Force an Open or just stop viewing the order? When you say I don't want to view the order in the Form.Load event you are calling Form.Close() which your Form.FormClosed event doesn't know why the Form is being close. Is that the problem? Does it matter why the Form is closing and your ownership variable is blank? If it matters you'll have to keep some sort of state in your Form or a ViewModel of the Form state to pass around. Indeed I had to very slowly write this out on a whiteboard to figure out what I should do. I added a bool variable to determine if when the form is closing it should reset it. If the load event successfully updates ownership, bool iOwnIt = true, when the closed event is called I wrapped the giveUpOwnership method in an if (iOwnIt){} If you hit no on the MessageBox in the load event, the variable hasn't been set yet so the closed event doesn't go inside the if statement.
|
# ¿ Dec 17, 2012 19:13 |
|
Success... after putting my rather frustrating project on hold for a few months, I finally figure out how to use app.config to have my entity framework model connect to different databases. It only took a three hour WebEx with a senior programmer to unscrew half the project. While I'm glad he was able to fix the problems in the designer constructor, we ended the meeting on a cliffhanger where he didn't think we could use app.config to change the configuration file at runtime and wanted either to comment/uncomment a connection string in the config file or change the connection string in the class (which genereated exceptions due to readonly problems), or have a separate model for each database. I'm thinking that doesn't seem right, so after the meeting I added the string in app.config and after some minor fixes, got it working. Now I got a WebEx tomorrow to show him how it works.
|
# ¿ Dec 27, 2012 02:37 |
|
aBagorn posted:Would you mind explaining? What would you like explained? Once I learned we access the connection string for entity framework through ConfigurationManager.ConnectionStrings["name"].ToString() and the connection string for SQL commands through ConfigurationManager.AppSettings["key"] I created variables for the key and name that were changed with a ComboBox. It was not knowing how to access the different connection strings that was getting me stuck.
|
# ¿ Dec 27, 2012 18:49 |
|
Some stuff I've been going over the past couple of days... Problem 1: I gave a program I made to a technician which to my surprise did not work. SqlException The SELECT permission was denied on the object. It worked on my machine because programmers have more database permissions than technicians. Solution1: I looked at a program my coworker wrote to see how he solved it. The difference is in the app.config file that stores the connection strings. Instead of using Integrated Security=true he had the SQL Server User ID and Password in the string. Problem 2: I was concerned that having our SQL Server information in an easily accessible plain text format was not a good idea. Solution 2: I added a SQL call in the code to a table that every user has access to that verifies the user is in a list then takes the value received from app.config and replaces Integrated Security = true to the SQL login in the program. Problem 3: That leaves the people who can get our password to those who can read the MSIL files, and the boss wants to minimize stuff like passwords and SQL hard coded in the application. Result: He recommended going back to solution 1 and not worrying about the password being in plain text at this time. For the future, what is the preferred way of handling this security vulnerability? I've tried looking up encryption for app.config on Stack Overflow and YouTube which resulted in different and relatively complicated results.
|
# ¿ Mar 21, 2013 20:57 |
|
Here's my headache for today. I have a DataGridView where I want certain columns centered, but changing the Alignment property seems to have no effect. After the DataGridView is populated I can alter the alignment of the column headers, but not the subsequent rows.code:
edit: I needed a fresh mind to figure this out... code:
Crazy Mike fucked around with this message at 17:47 on Jul 1, 2013 |
# ¿ Jun 28, 2013 23:42 |
|
A coworker asked me why I write so many static classes/methods. I said that I don't want to have to create a new object every time I want to use that method. In this case the class and methods are for running SQL queries to populate DataGridViews or update tables. She is concerned that static methods are more likely to result in memory leaks or have a bigger footprint. Is that a valid concern? Should I rewrite this class so it isn't static?
|
# ¿ Jul 10, 2013 17:52 |
|
Ithaqua posted:Just a heads up: If you're looking to get a Microsoft cert, 70-483 (Programming in C#) is ridiculously easy. I took it today on a whim (and because my employer set one of my 2013 goals to be "get a cert"), and I scored 975/1000. I'll probably buy the Wrox book first, but this will definitely be on my radar.
|
# ¿ Jul 22, 2013 17:50 |
|
Today's problem: I am trying to filter a DataGridView based on a column containing a TextBox value. The DataGridView's DataSource is set to a DataView so I can use its RowFilter() method. The TextBox Text changed event contains two methods. One that sets the filter, and another the reformats the DataGridView Columns since the filter resets the columns to defaults. If I type in the TextBox too fast, then the FormatColumns() method runs a for loop on a count of rows larger than it should, resulting in a Data Error and empty cells/rows in the DataGridView beyond what the filter returns. If I comment out the FormatColumns() method, there is no Data Error, but I lose my column formats. How do I ensure the FormatColumns() method has the right count of rows to operate on? The pertinent code is similar to the following:code:
code:
Crazy Mike fucked around with this message at 19:42 on Jul 30, 2013 |
# ¿ Jul 29, 2013 21:22 |
|
Remember a few months ago when I noticed that our app.config has our database connection string user name/password in plain text and that could be a problem? Well we're finally getting around to fixing that. One suggestion given here was to use integrated security and handle the user permissions for the application. That's a pain in the rear end that no one in here wants to be saddled with. I've been told we can't have a webservice handle the connection because we don't have the right hardware or something. Now that leaves us with the option of encrypting the app.config. When we use the ClickOnce deployment, there are multiple config files put on the user's machine, so we have to go up a directory and hunt them all down to encrypt them. Luckily someone else solved this problem which we borrowed liberally from. In the Program.cs file we call EncryptAllConfigs() right before Application.Run(new form()); code:
|
# ¿ Sep 16, 2013 21:01 |
|
Dietrich posted:Just hard code it. I've tried to convince my boss that this was getting circular and we should just hard code it. He still wants to see this encrypt app.config/hiding the folder thing instead.
|
# ¿ Sep 16, 2013 22:54 |
|
How do I get started with Unit Testing? I have been asked to update one of my programs and figured this might be a good time to practice this much hyped skill. Some things I have to do:
How many of these tasks are candidates for testing? Starting with adding a scroll bar I run into the problem that the TextBox is private and various websites saying either we don't need to test private objects or make them all internal and change the assembly info. For practice I made it internal just to see if I could write a test, which led to a NullReferenceException. code:
|
# ¿ Oct 3, 2013 01:36 |
|
I'm still working on my WPF Bulk Email program. One of the changes I made was switching the email body from a text box to a rich text box. Email content is saved in the database in rtf format. After choosing an email, I use an rtf to html converter I found somethere to have the mail sent in html format. The next improvement is to have images sent in the email. When the images are saved in the rtf file, they do not get sent with the html conversion. Online examples show the email being built in html and the images stored locally instead of the email/image coming from a rich text box. Where should I start looking for progress on this issue? Is using a rich text box to create and store emails and then converting to html the wrong approach for this type of problem?
|
# ¿ Jan 9, 2014 18:08 |
|
My problem for today: How do I get the source of a Model Validation error? We start off with: code:
I can build something like in this stack overflow question. code:
code:
|
# ¿ Apr 11, 2014 19:23 |
|
|
# ¿ May 22, 2024 16:42 |
|
I'm starting to take a deeper look at http://www.codeproject.com for introductory projects on various topics in the attempt to expand my knowledge base. Are there any other sites like that you can recommend, preferably with better written explanations?
|
# ¿ Jun 18, 2014 17:31 |