Jump to content
Xtreme .Net Talk

Nerseus

*Experts*
  • Posts

    2607
  • Joined

  • Last visited

Everything posted by Nerseus

  1. Have you picked a language to learn? How about platform (windows, web, mobile, etc.)? Are you going to use Visual Studio or some other IDE? What kind of project do you want to build eventually - database backend, games, tools, etc.? A good starting point is Microsoft itself: http://msdn.microsoft.com/developercenters/ If you want to learn C# or VB.NET (for example), follow the links for that language and then look on the right for "Getting Started". It starts with a link for "Fundamentals". If code samples are more your style, there's a link for "101 samples". If you like reading books, I like most of the O'Reilly books and the MSPress books. The "Essential NNN" books are nice. For C# I really like the "Essential C#" book by Fritz Onion. The one for .NET 2.0 isn't out yet so you may want to wait if you're jumping into 2.0 (and I would, if you get to choose). If you're used to Java, try the following link: http://msdn.microsoft.com/vstudio/java/ -ner
  2. If you wanted to bind to the DefaultView, then cast the DataSource back to a DataView instead of DataTable. You would do that if you wanted to bind to a filtered or sorted list of records - things the DataView lets you do. -ner
  3. They must be deleted separately - a DELETE can only work on one table. You can use alternatives, if your DB has the features. For example, in SQL Server you can turn on cascading deletes (delete from the parent table and it will delete the child rows). You can also code similar functionality in a trigger. It is BY FAR much more common to do the two deletes yourself, deleting from the child tables first and then the parent. I've worked with both kinds of companies - those that prefer to do deletes "by hand" and those that LOVE triggers. I only recently learned about the ability to do cascading deletes and my company's DBA doesn't like them. I trust him enough to take his advice. -ner
  4. About mskeel's comment ("...wigged out..."), I edited PM's message to turn off smilies. The line "Person:Display();" was interpreted as ":D" and, I guess in the code brackets, turned it into a big mess! -ner
  5. Ah, code! First the questions you asked about... You are already doing "substring" parsing (you use Mid(), a VB6 leftover). Some people define a line from their flat file in terms of Regular Expressions (using the RegEx object) and let that object do the parsing. It's very readable code (maybe not the regular expression itself), but slower than finding chunks of a string using Mid. BCP is the fastest way to get data into the database. bcp is a command line tool for SQL Server that takes an input file and a layout file (defines the fields, the delimiter, whether strings have quotes on them, etc.) and sucks the file into the table - VERY fast. DTS is the next best thing. In fact, if you design DTS correctly it will use bcp behind the scenes. It does allow you to "transform" the data, by sticking a piece of VBScript in the middle. In other words, it will generate a default script for you along the lines of: Sub Main() DTSDestination("Field1") = DTSSource("Field1") DTSDestination("Field2") = DTSSource("Field2") End Sub In there you can write your own logic, including subroutines and more. DTS is also very fast and allows you to tweak the reading/writing. For small to medium sized complexity, I'd use DTS over a custom EXE. Since you're using VS2005, you may be able to use the new SqlBulkCopy object. I admit I haven't had a chance to try it out yet, but it supposedly lets you write your VB.NET application as you want, and take advantage of BCP for speed. Now, for your sample code: One of the first things I would do is change all the string variables to use StringBuilder object. Every time you concatenate a string, it must allocate space for the new string and then copy the old string plus the new to the new location. Here's your code with some "dings" for each string copy: ' Ding 1 for the ReadLine() method If Len(input) > 15 Then ' Ding 2 SQL = "INSERT INTO badges (..." For X = 1 To UBound(FileTmplt) If DTypeArr(X) = 1 Then ' Ding 3 TmpVal = Mid(input, strCnt, FileTmplt(X)) ' Ding 4 (maybe more, inside of RepSngQut) TmpVal = ADO.RepSngQut(TmpVal) ' Ding 5 (I think only one ding, although multiple strings are concatenated) SQL = SQL & "'" & TmpVal & "', " Else ' ... End If Next X ' Ding 6 SQL = SQL & "'" & FileSrch & "')" ADO.ActionSQL(SQL, Cnn) WriteToLog(FileLog.Current, "Reading Line") End If As the example shows, there are 6 dings (string copies) for each line in the file. If your file is 10 meg (relatively small for some jobs), that's like reading and copying around 60 meg of data. Before making any changes, I'd do some profiling to see how things look before/after. Some changes may help, some may not. As you pointed out, you may also try using SqlParameter objects - you only have to build the collection of parameters one time, then reset the values on each loop. You may also try the good old do-it-yourself-batching. That is, save up 20 to 50 of the final SQL statements into a string and execute them all at once. So the string will look like: INSERT INTO badges (AssmDate, Acc, Loc, WearNum... INSERT INTO badges (AssmDate, Acc, Loc, WearNum... INSERT INTO badges (AssmDate, Acc, Loc, WearNum... Then one call to ADO.ActionSQL(SQL, Cnn) to commit them all. May take a little extra work for logging, to handle problems with failed logs (like a separate routine that loops through the big string and commits each INSERT one at a time in case of bad data). -ner
  6. I believe that MS designed .NET (and all Windows apps that use DLLs) to work as you describe. There is no "automatic" loading of DLLs because they're referenced, there is an explicit Windows call to load a DLL. That call is usually made for you in .NET whenever you use something contained in that DLL. If you want all the DLLs to load when the app starts up, you'll have to have some code to create or reference something in that DLL. You could probably have a static class with a static method Load() to do this. -ner
  7. Going faster can mean lots of things. Let us know what you're currently doing so we can offer more help. Here are just a few things that may come up: 1. DataSets with DataAdapters will be slower than straight Command objects (using ExecuteNonQuery for example). 2. Parsing the file with Substring will be faster than using Regular Expressions. 3. If you're using SQL Server 2000 maybe you can use bcp or DTS (Bulk Copy Program and Data Transformation Services). 4. If you're using SQL Server 2005 maybe you can use Integration Services (the new version of DTS that let's you write a Visual Studio application hosted inside of SQL Server). 5. If you're using .NET 2.0 with SQL Server you may be able to use the new SqlBulkCopy object. If you just want tweaks to what you currently have, let us see some of the code you're using so we can offer specific help. -ner
  8. Here's a rundown of the "find's" that I know about. You can find more (pardon the pun?) by using Tools->Options->Environment->Keyboard and entering "find" in the box labeled "Show commands containing:". Ctrl-F - Quick Find - the standard find. It can search in the current file, selected text only, current project or whole solution with lots of other options (Wildcard, Regular Expressions, etc.) Ctrl-Shift-F - Find in Files. This does a little more than the Quick Find as it searches ALL files, even those not included in the project. You can't really do that with the Quick Find. Ctrl-F3 - Find (whatever is under cursor). This is like highlighting a word/symbol and pressing Ctrl-F and then Enter. In other words, if I highlight a variable named "counter" then press Ctrl-F3 will jump to the next occurrence of "counter". Ctrl-I - incremental search. This is what mskeel saw. You press Ctrl-I and start typing and it finds the next match based on what you typed. F12 - Go to definition. Jumps to the code (or object browser) where the variable is declared. If you have a method call highlighted, it jumps to the defintion of the function. Shift-F12 - Go to first reference. Like F12 only it goes the other way. Highlight a method name where it's declared and press Shift-F12 to take you to the first call to that function. Shift-Alt-F12 - Find Symbols. If you highlight a variable or Class name and press Find Symbols, you'll get a listing of all occurrences of that name. It's like pressing F12 on steroids. Output goes to a toolbar window. As with any "toolbar" window (not sure of the official name), you can press F8 to cycle through all matches. That works with the Find Symbols results (from above), Find in Files results, as well as things like the Error List window (if you have any build errors). There are a few other "find" items that I don't know anything about, such as "Edit->BriefFind" and "Edit->FindAllReferences". I didn't list the more common ones like F3 and Shift-F3, which most people know about. -ner
  9. When you set the SelectedIndex, you trigger an event (SelectedIndexChanged, I think). Do you have code there? I don't know if setting the SelectedIndex property is enough to cause the collection to change by itself. If it is, then it would violate the usage of the foreach. In that case, you can do one of two things: 1. Move the line of code that sets SelectedIndex to be outside the loop. You can check Ctr to make sure it's less than .Count and if so, set it. 2. Change the foreach to a regular For loop. I'd probably go with #2 in this case - but I would first check if you have code in the SelectedIndexChanged event to see if that would modify the combo's items. -ner
  10. I believe MS has stopped putting "big" easter eggs in their products. They took some heat a few years ago for "wasted resources" and other such nonsense. People have enough ammo when it comes to complaining about MS products so they decided to cut them out. That's not to say they don't exist, but I think the official word is no more easter eggs. It's too bad - I thought it was cool to play the "flight sim" thingy in Excel and the first person "shooter" game, too (where you find the secret room with pictures of the developers). I can't remember which versions or products, but I found them all by using the tips on the eeggs.com site. -ner
  11. As far as the SQL code goes, in all the databases I've worked with you must have the FROM before the WHERE clause. If the alias is for the column, you need to move that, too. See this: Change: SELECT SUM(nec_amo) where nec_type = 'Food' As total from nec To: SELECT SUM(nec_amo) As total from nec where nec_type = 'Food' As far as the .NET code, that's harder to tell. There are lots of assumptions to make - for example, is daNamePhone declared to be a DataAdapter or some derived type? I hope this is sample code as I'm not sure how the name daNamePhone, which implies something about a name and a phone, relates to the query which appears to be the sum of something based on a food. :) -ner
  12. Thanks for the replys! Your replies were right on and solidify what I was thinking - much better argued than I was thinking. I'm glad I asked! -ner
  13. We have a small debate at work and I'm wondering if there's any information on going one way or the other on this. The setup is that there exists a database utility class - a class that serves only to expose some static methods. It looks something like this: public class DataAccess { protected static readonly string connectionString; static DataAccess() { connectionString = ""; // Code ommitted - assumes it gets the connection string } internal static DataSet ExecuteNonQuery(string commandText) { // Code to create a DB command object, set the connection string // and call ExecuteNonQuery // Also handles exception handling by logging errors and other misc details } } So the general syntax for using the static method is: DataAccess.ExecuteNonQuery("procName 'hello world'"); Now the argument comes up over whether a specific Data Access Layer class should inherit from this class or not. Here's a sample that does inherit: internal sealed class CustomerDataAccess : DataAccess { // Private constructor so it can't be created - in 2005 you'd declare the // class as static private CustomerDataAccess() {} public static void SaveCustomer(DataSet ds) { ExecuteNonQuery("UpdateCust '" + ds.GetXml() + "'"); } } Again, ignore the syntax of passing params to a stored proc as a string without any SQL Injection checks. In the above, I'd rather NOT have CustomerDataAccess inherit from DataAccess. The only change is that the call to ExecuteNonQuery changes to: public static void SaveCustomer(DataSet ds) { DataAccess.ExecuteNonQuery("UpdateCust '" + ds.GetXml() + "'"); } But others argue that by inheriting from DataAccess, you're declaring your intentions that this is a DataAccess component and the method calls "look" like they're part of CustomerDataAccess. I'd argue that they're NOT part of CustomerDataAccess but that they're still part of DataAccess since they're static. I guess I don't see the benefit of inheritance in this case a both classes are really utility classes. Any thoughts? -nerseus
  14. Also, you can take advantage of the "using" statement to create collection "classes". For example, you can use a generic List<> to create a collection of Customers. You can do this as easily as: class Customer { /* Details Omitted */ } // This is in a separate file from class Customer class Test { private List<Customer> customerList; } If you have this a lot, you may want to create a class like so: class Customer { /* Details Omitted */ } // This is in a separate file from class Customer class CustomerList : List<Customer> { /* No code - simple class */ } // This is in a separate file from class Customer class Test { private CustomerList customerList; } But you can also use the "using" statement to create a fake class named CustomerList. For example: class Customer { /* Details Omitted */ } // This is in a separate file from class Customer using CustomerList=List<Customer> class Test { private CustomerList customerList; } -ner
  15. There are two common ways to get an identity out of SQL Server: @@IDENTITY and SCOPE_IDENTITY(). It should be as simple as adding a SELECT to your SQL. The string becomes: INSERT INTO dbo.EmployeeMaster (EmployeeName, EmployeeInitials, EmployeeEMail) VALUES ('Oswald, Steve', 'SJO', 'StevenJOswald@gmail.com') SELECT @@IDENTITY Then change your C#/VB code to use the ExecuteScalar method call (where you are probably currently using ExecuteNonQuery). If you need more details let us know. If so, please post the relevent C#/VB code that executes the SQL. If you're using SqlParameter objects for example. -nerseus
  16. I tried this as well. At first, I got the same error as you. I used the GUI to change the compatability to 90 (right-click the DB, select Properties, go to the Options tab, Compatability Level). I then disconnected my server from the MAnagement Studio and reconnected. Now when I open Database Diagrams it says something about the objects aren't there, do I want to create them. I said Yes and all works well. -ner
  17. Not much is said about the new ?? operator (maybe it's not an operator - who knows?) but it's there in C#. It's meant to work as a coallesce on nullable types, which can be declared with the new ? syntax. For example: int? x = null; // Same as Nullable<int> y = null; The new syntax of "int?" declares a generic Nullable type, but easier. Most people know about this. What I just learned is that to return a "default" value of a null int, you can use the new ?? syntax. For example: int? x = null; int y = x ?? 0; This says, if x is not null, assign the value to y. If it is null, use the righthand side, or 0 in this case. You can use any expression in place of 0, including a property, method call, etc. - including cascading ?? operations. For example: int? x = null; Nullable<int> y = null; int z = x ?? y ?? 0; // Sets z to 0 y = 5; int z = x ?? y ?? 0; // Sets z to 5 -nerseus
  18. As far as I know, and what I've seen, if you want a specific format for numeric data in the XML, you'll have to do it manually. If you have a schema included in the XML (or some other kind of schema information), you may also have to define that element as text instead of numeric. -nerseus
  19. I haven't tried this, but when you load the XML into the DataSet I assume you're using ReadXml()? Have you tried the param XmlReadMode.InferSchema? I wonder if that would build the schema for you, and fill in any missing data? -ner
  20. You said it doesn't blow up at the top, when you first reference tlbSearch.Buttons(0) so something must be clearing that collection. I'd step through code to find out when it's getting cleared. -ner
  21. I'm not sure what language you're using - is that Javascript? In .NET, you'd use the Subtract method of a DateTime variable to get a TimeSpan object, as in: DateTime d1 = new DateTime(2006, 06, 29); DateTime d2 = new DateTime(2006, 07, 03); TimeSpan ts = d1.Subtract(d2); Then you could check ts.Days, for example, to get -4. Or change it to "d2.Subtract(d1);" to get 4. -nerseus
  22. Nerseus

    Linked List

    It would greatly help to know what you've already done and what version of VB.NET you're using. In the 2.0 framework there is a generic type called LinkedList - are you using that? Or, is this an assignment to create the linked list from scratch? Since it's against policy to "do" homework assignments for people, we can only offer advice on what you've already done or offer suggestions/partial solutions to code where you're stuck. -ner
  23. Yep, changes happen all the time and you can't always predict them. Don't get caught up in over design (paralysis by analysis) on the next project simply because you want to prevent the problems you had this time around. Sounds like you're going through the startup troubles of an early phase of development - building that "framework" of what you use. Lookups, including "all access" and "secured access" differences, are "core" and can be reused on other projects. So yeah, having to change your classes, archictecture, etc. is a pain but it's a mostly one time thing. Wait until you decide that cacheing lookups locally sounds like a good idea - another change. Then you'll think "hmm, I can also cache them on a webserver so I don't hit the DB so often" - another change. Then you'll realize that some lookups can be added to "on the fly" so you need a way to clear the cache or alert clients to re-get their lookups when additions occur - another change. Even simple things can change over time - don't worry about it! If you have good classes now, keep it up - keep the changes in "good" condition. You'll almost always regret it if you try to skimp. Of course, there's also the rule of KISS - Keep It Simple Stupid/Silly (depending on the G vs. PG rating). In other words, maybe the lookups could be hard-coded in a class and not read from a DB at all. Part of all these choices and designing/coding for them moves you up from a developer to an architect - a good chance to ask for a raise :) -ner
  24. This sort of thing, on the web, will have to be done via javascript or some other client side scripting. Using the codebehind of ASP.NET means that the page is still kept in the buffer until the page is done. There are ways to flush it, but it sounds like you want something else. What's the effect you're going after? Just a simple "Please wait..." that moves or something much nicer, that actually shows like an accurate progress bar? -ner
  25. Does it have to be regex? Sounds like you just want IndexOf twice? -ner
×
×
  • Create New...