Nerseus
*Experts*-
Posts
2607 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by Nerseus
-
C# - Copying Rows between DataTables
Nerseus replied to EFileTahi-A's topic in Database / XML / Reporting
The Copy method is actually at the DataTable level. If you look at the code, I go through the DataSet to get to Table sub 0. It's the same as: DataTable newTable = ds.Tables[0].Copy(); // Same as DataTable myTable = ds.Tables[0]; DataTable newTable = myTable.Copy(); So in the above, pretend that all you have is myTable. Regardless of where it came from, if it's an active object (not a null reference) you should be able to Copy it, Clone it and then loop through its rows. -ner -
Maybe he wants to enforce a key, maybe between a lookup table in one dataset and the transactional data in another? My work usually splits up the datasets this way (sometimes more). When I've needed it, I've included the lookup table in both datasets. Mostly I would handle this through custome code to enforce the constraint, treating it like any other business rule. Normally a user would only get to change the value through a DropDown or some other means - effectively forcing them into a constrained value. -ner
-
Maybe we could use a standard for subject lines to find what you want, something like: Book Review: Effective C#... Tool Review: DevExpress XtraGrid control... Book Advice? Effective C#... Book Advice? Novice VB.NET developer... -nerseus
-
C# - Copying Rows between DataTables
Nerseus replied to EFileTahi-A's topic in Database / XML / Reporting
Yes - you can use either code snippet depending on what you want. I'm not sure if your DataTables start at null or if they're already defined (and possibly populated). If you need help, let me know more about what you've got and what you're trying to get to. -ner -
Is the database in step 7 the same as that pointed to in step 8? If it is, why use the "IN" keyword? Is there another need for this, such as having to do this across databases in the future? If so, let us know - maybe you need to "flush" Access before it commits the changes? Also, above step 7, do you have any code that would start a transaction or do anything that would make you think it's not committing the data immediately? -ner
-
C# - Copying Rows between DataTables
Nerseus replied to EFileTahi-A's topic in Database / XML / Reporting
All rows? Try this: // Copy Table 0 to a new table named "MyNewName" DataTable newTable = ds.Tables[0].Copy(); newTable.TableName = "MyNewName"; ds.Tables.Add(newTable); If you only want certain rows, use ImportRow. Below I copy the first 3 rows of table 0 into a new table. Assumes 3 rows exist :) DataTable newTable = ds.Tables[0].Clone(); newTable.TableName = "MyNewName"; for(int i=0; i<3; i++) { newTable.ImportRow(ds.Tables[0].Rows[i]); } ds.Tables.Add(newTable); -ner -
I haven't look at the code, but the SharpDevelop project already has a working, OpenSource IDE that looks nearly identical to Visual Studio including regions in code. If you want to do this all yourself, I'd look there to see how they did it. -ner
-
I would guess that the constructor of a string that takes a char is there because it was easy to code in assembly - simply pushing the same value into memory x number of times. To shove a string into memory x number of times requires more work and, I would guess, doesn't come up very often. I've never had the need to prefill a string with anything other than a single character. -ner
-
Creating a "BETWEEN dates" SQL query...
Nerseus replied to EFileTahi-A's topic in Database / XML / Reporting
@falcon: I don't think he has a problem with Crystal reports, just with straight-up SQL. @EFileTahi-A: I was hoping you'd have already written a small test app to test your query. If something doesn't work for me as I think it will, I try and write a smaller version to test out why and to experiment. See attached for a sample project I wrote. The included Access database has one table named "historico" and two fields. The code is C# but should be straightforward and pretty small. I don't have XCeed so that part wouldn't work for me. I'm not sure what part of XCeed you are using but it sounds like your problem is with straight ADO.NET running a query. Here's the query I used. I used the date format "mm/dd/yyyy" although with all of your tests (in the other posts) you always have the day and month being the same day, so it won't really matter :) SELECT * FROM historico WHERE dataagend between #01-01-2005# AND #12-12-2005# -ner ADOTestAccess5.zip -
What do you all think about a new forum for "Reviews"? Topics would be limited to reviews of Books, Training Courses, 3rd party products, etc. I was just thinking, "Wow, these new books I just got are excellent!" and I wanted to tell everyone but didn't really want to post something in Random Thoughts. I've also linked to Refactoring: Improving the Design of Existing Code at least 3 times and was thinking it would be nice to have one place to forward everything to. I was thinking the forum would also be good to ask advice about books or 3rd party products. Getting advice from those that have used the products would be best. The one thing that worries me is the participation level. No point in having a forum if no one posts! I figured I'd toss this one out to the community to see if anyone thought it sounded useful. I'd start it off by throwing in a couple of short reviews on the following (all of which I would highly recommend): Refactoring: Improving the Design of Existing Code Programming C#, Third Edition Effective C#: 50 Specific Ways to Improve Your C# Design Patterns Explained Design Patterns in C# Test-Driven Development in Microsoft .NET Expert C# Business Objects -ner
-
Creating a "BETWEEN dates" SQL query...
Nerseus replied to EFileTahi-A's topic in Database / XML / Reporting
Can you zip up your code and database, or a sample? The query you have (with the #) should work fine if the table is defined as expected. -ner -
Can you define what you mean by lag? To me, you're saying the code finishes executing but the database doesn't reflect the change for a few seconds? That's crazy! Are you saying that the command takes a few seconds to run? You'll have to give us more info. Maybe you're updating 10,000 rows (you didn't specify a WHERE clause) and it just takes that long. Maybe you're saying that the code seems to be "doing something" for a few seconds before actually doing the update. You'll have to track that down, if you're seeing it. Maybe you're network connection is 56k modem connecting to a DB across the Atlantic. Also, am I to assume that 2/3 is not two thirds, but 2 or 3? -ner
-
This is a bit old (2002), but should get you started: http://vbcity.com/forums/topic.asp?tid=12044 The idea is that you'll have to declare all functions yourself as PInvoke calls (calls into a native code DLL). You can definitely do this in VB.NET, but it might take a bit of... endurance to get the calls made correctly. I know nothing about interfacing with MSFS so I can't help. I will say that if you need to create a DLL that's compatable with the game, then it's VERY unlikely that any .NET DLL will work for you. If you just need code to interface with their DLL, then you might be able to get something working. Good luck, ner
-
You'd probably be better off using a Command object's ExecuteScalar function, which is meant to be used when you have exactly one value being returned from a query. If you want to use the DataSet, try something like: string s = oRecs.Tables[0].Rows[0][0].ToString(); There are a LOT of assumptions there, but you get the idea. -ner
-
MS won't make a version of Windows that doesn't support VB6 for a very long time. As for the API calls, most of the common ones will be supported even though there may be newer alternatives. I would say that most applications written in VB6 have a VERY small percentage of code that relies on an API. API calls to set tabs in listboxes, get domain names, etc. will surely be supported for a long time. MS's "mainstream support" for VB6 ends on March 1, 2005 - less than a month. I'm just now having to go back and give estimates and fix some code I wrote in VB6 almost 6 years ago. The company that now owns the application we wrote LOVES the application, sells it and has no plans to upgrade to .NET in the forseeable future. It's one of many large, stable, easy-to-maintain apps written in VB6. Why am I saying this? My point is that MS may stop mainstream support for VB6, but it's still in use and will be for a long time. -ner
-
If the property masks a private field, make the field protected - thereby allowing the inheriting code to modify the field directly. Then you only expose the get property publicly. Not quite as clean, but might work out. If you want to wrap the setting of the field in a property, maybe make one a function "SetProp" or another property with a different name. I don't think you can do what you were originally asking directly in .NET though, just workarounds. -ner
-
Don't forget, you can program in VB6 for as long as you want. Just because MS ends its support doesn't mean you have to stop using it. VB6 is great for prototyping, especially if you don't know the .NET framework. As I said earlier (I think), there are language changes (fairly big, but easy enough to learn and definitely worth it) and the addition of the framework. Both take a bit of time to learn, but your investment will pay off. Trust me, if you invest the time to learn .NET you will get that same "wow, this is cool!" feeling you did when your old app interfaced with your custom board. It's overwhelming, but only at first. If you'd spent as much time reading and working through a few examples instead of posting here, you'd be neck deep in .NET by now! As a suggestion if you want to try .NET again, try working on a few small applications that DON'T do anything "special" such as communicating with a comm port. Try a standard console app and piddle with classes, properties, etc. Try out some Shared functions to see how they work. Mess with inheritence a bit. I would guess 8 hours of piddling would get you about 80% comfortable with .NET. -ner
-
For you, I would recommend C++ over C#. Sounds like you're mostly "playing", making mods and such, and for the most part that's going to be easiest in C++. I suspected as much since you said you did a lot of "API stuff". That usually implies tinkering around more than working on a full-fledged application. Most "real" applications rely a lot more on already written code - the .NET frameworkd for example - and a lot less on the API. I think you'd do well to get a C++ language book - avoid a "Visual C++" book as they tend to focus a lot on .NET and Visual Studio itself, especially the wizards. Learn the language and you'll do much better. If you start to read up on stl or templates in general, I'd suggest shying away for now. Learning templates is a good idea, but only after you know the language well enough to implement them and more importantly, debug them. -ner
-
Not sure what you're doing with the DataView after you apply the filter, but... If you want to get at a particular row and it's data (and not for binding), then the Select method is quite a bit faster: DataRow[] rows = myDataSet.Tables["Customers"].Select("Country = 'Argentina'"); if (rows.Length > 0) { // Found at least one match: foreach(DataRow row in rows) { // Do something with each matching row // Don't delete in here, this is a foreach :) } }
-
Whether you pick C# or C++ is up to you. Here's my two recommendations: For C++: C++ from the Ground Up by Herbert Schildt For C#: Programming C# by Jesse Liberty I've used both extensively and keep them handy at all times. I make those suggestions first, since you sound like you don't know what you want to program (using the Windows API or "pointers" only provides a means to an ends, it doesn't tell us what you want). I suggested books about the languages, which are key to being a good programmer. If you have a certain program, or type of program (such as Games) in mind, I'd still strongly recommend those books. Another great book that everyone should read, regardless of language: Refactoring: Improving the Design of Existing Code by Martin Fowler -ner
-
What's the error you get? What are some of the values you use? Try changing the line that sets myInsertCmd to first build the string into its own variable, then passing that. That way, you can examine the string before you make the call. For example: Dim sql As String = "INSERT INTO FileStorageTbl (Revision,FileType,Version,Title,User,Name,Date,Time) VALUES ('" & strRevision & "','" & strFileType & "','" & strVersion & "','" & strTitle & "','" & strAlias & "','" & strName & "','" & strDate & "','" & strTime & "')" Dim myInsertCmd As New OleDb.OleDbCommand(sql, myConn) -ner
-
Is this for a career move that you're learning .NET, or just to have fun? If it's just for fun, why upgrade? Heck, I'd stick with VB3 if you can find it. That thing was LIGHTNING fast. When I go back to work on VB6 projects, I notice just how FAST a Windows program starts up compared to .NET in the IDE. But, the changes to VB in .NET are definitely worth the extra effort. It was a bold move for Microsoft - and they've taken a LOT of heat. Trouble is, it's hard to support all VB users. Many professional VB users wanted a more robust environment and better OO support and that's what they got. Other users that cry for the days of QBasic got... well, they have emulators :) I feel for you, but no one can force you to use .NET if you don't want to. -ner
-
The crew has morals, or morale? Morals is not shooting a missile at a civilian craft. Morale is them getting testy because you've had them out at sea for 2 years straight... -ner
-
Each class deriving from Component gets a DesignMode property. A form or control should have this. For example, in Form_Load: private void Form1_Load(object sender, System.EventArgs e) { if(!this.DesignMode) { // Put some code here when running "for real" } else { // Put code here for Design mode. // This is when showing the form in the designer } } -ner
-
First things first... VB.NET is a lot harder to use than previous versions of VB, especially in the beginning. Two things jump to mind: 1. You have to save files before you can even run your first project - in VB6, you could just start a new project, change code and run without ever saving. 2. You don't really have any "built in" functions - everything you had "built in" with VB6 is now part of the .NET framework. If I had to start over again, I'd start by reading a copy of Refactoring: Improving the Design of Existing Code. It gives you a sense of freedom to code how you want now (procedurally) and later change the code to OOP. Obviously, if you know OOP inside and out now, you'd start that way. But if you're like most of us, you learned procedural programming and a jump to "everything is a class" is a bit harder to grasp. It will come easier, I promise. If you haven't already, I would definitely spend some time just learning the language - Console Apps. Avoid windows apps for awhile as they will taint what you do. For example, a Form is nothing more than a Class that inherits from a System.Windows.Form class, which provides automatic drawing and other stuff. When you look at the code, a lot is done for you - and maybe not the way you'd expect. As for certification... I think it's a good thing, but only in a small way. I know of no company that would hire solely on that, or that would NOT hire because you weren't certified. I'd think of certification as a self-imposed, structured, testable, way to show YOURSELF that you know .NET. As for Windows or Web... As I mentioned, I'd learn the language first. Learn classes, events, properties, loops, etc. Then pick up the .net framework - classes that are provided to you. Then you can start learning Windows programming or Web, if you prefer. There is a definite difference and a definite destinction. Windows is "easier" since you don't need to setup IIS or other webserver to test anything. At my company, a developer usually hires for a "windows" or "web" position so if you want to concentrate on Windows, do that. Most of all, have fun! Go back "to school" and write a few dummy apps. Can you print 5 rows of asterics to the console? Can you play a "high/low" game? Can you make a mock store that offers 3 choices and adds up the totals? After you write a small app, try to enhance it - how could you make a new class out of something? How could you use an event to let some other code know when something happens? The idea is to think of what you might want the program to do and see if you know how to do it. Try and think of the idea first, then how to implement it - you'll find tougher problems that way. The End.