Jump to content
Xtreme .Net Talk

Nerseus

*Experts*
  • Posts

    2607
  • Joined

  • Last visited

Everything posted by Nerseus

  1. I've just finished installing the Whidbey technical preview on my home machine so I have more time to "play". Whidbey is the next version of Visual Studio (due in 2005). There is some seriously cool stuff in there! For one, partial classes. Similar to C++, you can now split class code among separate files. Class getting too big? Split it out. Basic Refactoring is now built in. Items like "Extract Method", "Promote to Interface" and more are there and VERY easy to use. If you've never heard of refactoring, check out this book. You can now rename a method and have Visual Studio go and find all references to the new name and update them. You can reorder parameters to a method and it will reorder the params passed to the method wherever you called it. You can now use Generics - similar to C++ templates. Rather than create a whole Collection class just to get a type-safe collection, you can use a template to define a variable as a typed collection. That alone will save me a TON of code. Another feature I haven't played with much yet is generic value types. You can create a Nullable int. So you can define the variable i as a Nullable int and use it exactly like an int. If you don't define it it will have a method like NullValue that returns true/false. So, no more questions on "does 0 represent a "null" int or should I use int.MinValue?". Awesome. They haven't added it yet, but I hope there's a way to specify the Output Type (win EXE or class library) as a configuration param. So, Release mode makes a class library while Debug mode makes an EXE. Also, if you've ever wrestled with the docking windows in Visual Studio, trying to get the properties window below the Solution Explorer or the Watch Window just right... they've redesigned how you dock windows. See the screenshot below - you now have little popup thingies that show you just where to drop a window. There are about 500 options on how to format your code, if you want to tweak indents (case, switch, the lines after a case, brackets, etc.). That's all for now... just totally impressed and can't wait to start using this next year! -nerseus
  2. Will it have the relation named CustomerOrder? -Yes Will it know the parent and child? -Yes You can also specify non-default behavior for relationships (like non-cascading deletes and such). If you use Visual Studio's DataSet editor, you can "visually" change the relationship. It works much like a real database tool, such as Access or SQL Server Enterprise manager. As you make changes, you can look at the XML by switching tabs. -Nerseus
  3. Look in the help, but this is by design - the first group (group 0) is an unnamed group. Look at the help topic under Group Constructs. Here's a snippet: -Nerseus
  4. You can use use the DataSet's ReadXmlSchema method to read an XML schema file. If you create a DataSet in Visual Studio (an XSD file) you can view the resulting XML. A sample key and relationship looks like this: This assumes two tables, Customer (with CustomerID) and Order (with OrderID). The "xs:key" sets up a primary key on teh customer table on column CustomerID. They key is called PKCustomer but could be anything you want. The "xs:keyref" sets up the relationship. In this case, linking the previously defined key PKCustomer and the OrderID on the Order table. <xs:key name="PKCustomer" msdata:PrimaryKey="true"> <xs:selector xpath=".//Customer" /> <xs:field xpath="CustomerID" /> </xs:key> <xs:keyref name="CustomerOrder" refer="PKCustomer"> <xs:selector xpath=".//Order" /> <xs:field xpath="OrderID" /> </xs:keyref> -Nerseus
  5. As I said, if you want what's "right", call Microsoft - they have a very large team that does nothing but answer questions on what versions/types/licenses you need for each type of software. If you know 5 users will be the most you'll need (a very small website), then MSDE will likely work. That's 5 current connections, which should generally support 20+ web users at once, depending on the type of web application. Otherwise the client will need to license SQL Server, which can get expensive quickly (based on number of processors I believe). I thought you were initially asking what version/licence YOU need to develop, which is a completely different licensing arangement. Basically, MS doesn't charge for the Development versions of SQL Server. There are exceptions, but the folks at MS can (and should) answer all your questions. -Nerseus
  6. Make sure your project is saving the resx file (if you're using C#, click "Show All Files" in the Solution Explorer to see the resx file below the form's cs file). That's the only thing I can think of if everything else is created from a default project with no other tweaks. Do you get an exception, or just no picture? You might also try loading the image at runtime to see if that works - just as a test. In Form_Load, put something like: imgTest.Image = Bitmap.FromFile(@"c:\temp\image.bmp"); If that works, then you likely have something wrong with the resx file(s). Not sure what the cause would be, but at least it's a start. -ner
  7. Do you mean you have an XML file that was created from a DataSet (the schema or data+schema)? If so, create a new DataSet then use the ReadXml method with XmlReadMode.ReadSchema. If this is custom XML that happens to have relations in it, we'll need a LOT more info. How did it get created? How do you know about relationships? -Nerseus
  8. Normally you'd use EXEC to call a proc and get the value back (or just call another proc in general). DECLARE @i int EXEC @i = sp_proc 'param' You might need parens, I can't remember: EXEC @i = sp_proc('param') As Joe mentioned, if you really want a prefix on your procs, I'd use something like "UP_..." instead of "SP_..." as SP is used for the system procs. Also, if the proc is simply returning a scaler and not doing any other work, I'd move it into a function. If the proc is doing multiple things, like updates or inserts and then returning the int, I'd keep it in a proc. -Nerseu
  9. I'd call MS to confirm, but I think if you're just doing development, you'd want the developer edition. It might be free, I'm not sure. We use our MSDN Universal license to run SQL Server, which can be used for development at no additional charge. -ner
  10. I don't think it's possible. -Nerseus
  11. I'd say work off the Format, not the parsed Delimiters. For example: // Given some generic format... string format = "[Name] :- [Code] - [sublet]"; // Replace the "[" and "]" characters with regular expression chars format = format.Replace("[", "(?<"); format = format.Replace("]", ">.*)"); string regExpression = "^" + format + "$"; // The rest of the code is the same string data = "Nerseus Bob :- ABC123 - 05f"; Regex regex = new Regex(regExpression); Match match = regex.Match(data); if(match.Success) { string name = match.Groups["Name"].Value; string code = match.Groups["Code"].Value; string sublet = match.Groups["Sublet"].Value; } If you don't want to "know" the names of each group, you can use ordianl positions. So change: string name = match.Groups["Name"].Value; to string name = match.Groups[0].Value; You could, if you needed it, get the group name from the ordinal. So to see that the groups are "Name", "Code", and "Sublet", you simply check the group's property given the position 0, 1, or 2. -Nerseus
  12. Make sure you're in Debug "mode", not Release mode. On the main toolbar there should be a combobox where you can change configurations. Or, under Build->Configuration Manager. -Nerseus
  13. All you have is an array of delimiters? Is this an array that's given to you or one you build yourself (or read from a config)? Ideally, you'd store the regular expressions instead of the delimiters, if you have the control. If you just need a general purpose "split" library that splits on a set of delimiters in a specific sequence and you don't know how many or how big each delim will be, you may want a custom regular expression like the one your pseudocode was showing. If you know there are only two or three sets of delims to look for, I'd go with the more readable named groups. If/when you have to modify this code a month or more from now it will be a lot simpler. -Nerseus
  14. It sounds like what you want is more than a simple split - I think you'd do best with regular expression groups. Here's a code snippet to extract what you want (I guess): // "Name :- CODE - SUBLET"; string expression = @"^(?<Name>.*):-(?<Code>.*)-(?<Sublet>.*)$"; string data = "Nerseus Bob :- ABC123 - 05f"; Regex regex = new Regex(expression); Match match = regex.Match(data); if(match.Success) { string name = match.Groups["Name"].Value; string code = match.Groups["Code"].Value; string sublet = match.Groups["Sublet"].Value; } The string "expression" is the regular expression. It defines 3 groups: Name, Code and Sublet. Each has a match of ".*" which means, match anything. In between each group is the other pieces of the match, which you don't care about except as delimiters. If you know that there will always be spaces around each delimiter, you could put spaces in your non-group matches. Something like this: string expression = @"^(?<Name>.*) :- (?<Code>.*) - (?<Sublet>.*)$"; -Nerseus
  15. Shaitan00, even with your "dynamic" code you still need to figure out Delim. I assume you "know" this from either a file or some other method. Once you have that list of delimiters, you can use Regex.Split. RegEx allows multiple delimeters, each being any size you want. For example: // Somewhere at the top: // using System.Text.RegularExpressions; string s = "Name :- CODE - SUBLET"; Regex r = new Regex(":-|-"); string[] s2 = r.Split(s); foreach(string s3 in s2) { Debug.WriteLine(s3); } The regular express is ":-|-". This says find a match on ":-" or on "-" (the pipe is an OR). -Nerseus
  16. ASP.NET is setup this way. To step through code on webserver will look everyone else out. Microsoft's suggestion and, in fact, their recommended approach, is to have each developer run the website on their local machines and only push up to a common server when they're done testing or want to share their code changes. My company decided not to have each developer run the website as the projects were changing so often that trying to keep everyone in sync with the latest changes wasn't deemed worthwhile. So for now, if we need to "step through" the ASP.NET code, we don't (in general). Instead, we write to the event log and check the results. It's a pain unless you have a general feeling as to where the problem might be. Occasionally, when time becomes an issue, we can let all developers know we're stepping through and then try to get in/out quickly. We have around 15-20 developers/QA people using one webserver at a time so it can't stay locked for too long. It hasn't caused too many issues unless you come across a really hard-to-find bug - about 30 minutes into writing event log entries and you start looking to strangle someone for pretty much any reason. -Nerseus
  17. Our DB Admin uses a SQL Compare Tool. I'm not sure if you have a budget for this or if you want to do it yourself. If you're looking for a tool, search google for "sql compare". I can get you the product our DBA uses if you'd like (it's probably between $100 and $1000... not sure. -Nerseus
  18. Nerseus

    Mdi

    You could try a number of approaches, two common ones come to mind: 1. Use the control's FindForm method to get it's hosted form then use that form's MdiParent property. 2. Keep a static reference to the MDIForm in a "global" type of class. This works well even when you use separate assemblies IF all assemblies know about the "global" class. For #1, use something like: // Event handler for the treeview, in some common class private void Tree_Click(object sender, ...) { Control ctrl = sender as Control; if(ctrl==null) return; // Not a control? Hopefully shouldn't happen // Get the form the control is on. Use this form's // MdiParent property below Form parent = ctrl.FindForm(); Form2 frm = new Form2(); frm.MdiParent = parent.MdiParent; frm.Show(); } For option #2, in Main (if that's where you create your MdiForm), you can set a static reference to the variable before showing it. Suppose you had a class like this: public sealed class GlobalVars { public Form MDIForm; } In Main, you might have code like this: static void Main() { frmMainForm frm = new frmMainForm(); GlobalVars.MDIForm = frm; Application.Run(frm); } Then wherever you need to get to the MDI form, you can use it like a global variable: // Event handler for the treeview, in some common class private void Tree_Click(object sender, ...) { Form2 frm = new Form2(); frm.MdiParent = GlobalVars.MDIForm; frm.Show(); } -Nerseus
  19. You don't necessarily have to do C# for everything. You could put the new type in a separate C# project and just reference it from your VB.NET projects. Of course for what you want (a new type with a lot of operator overloading), you'll need to know a bit of semi-advanced C#. If you're just starting out at programming or willing to make the move, maybe a move to C# is warranted. But, if you have a lot of time spent learning the ins and outs of VB.NET, you might try doing the minimum to get your class implemented in C#. For what you want (a direct assignment as if your type were a string) you'll need the implicit operator overloads (when you look up operator overloading look for the topics on "implicit"). -Nerseus
  20. No, a DataView cannot show data from more than one DataTable. I can think of two alternatives offhand: 1. Use expression columns in a DataTable that reference values from another table. 2. Use a custom class, like JoinView from Microsoft. For #1 to work, you have to have a relationship in your DataSet. The expression can use Parent and Child to reference the other table, depending on your relationship. The expression doesn't come without drawbacks. For one, they don't update automatically in all circumstances. For another, you can't use something like GetChanges if one of the tables that changed was in the relationship while the other isn't. Option 2 means using custom, potentially buggy, code. Also, if you want it in C#, you have to convert. I converted it to C# and it's been working fine for me but I don't use it to modify any data in the DataSet, only get a joined-view of data. Before you ask, No, I can't release the converted project - I've asked my boss and he said nope. It only took 3 or 4 hours and that included adding a custom constructor for my purposes (to automatically add all columns from one DataTable or the other). -Nerseus
  21. ...except he wanted one for WebForms. I can't help you with a control. I replied so that the thread didn't "die off" if someone thought it had been answered. -nerseus
  22. Also, even if your catch block were to throw an exception, the finally would still execute. A common example is: SqlConnection conn; try { conn = new SqlConnection("..."); } catch(Exception e) { throw new Exception("Couldn't open connection..."); } finally { conn.Dispose(); } Obviously not a very helpful block of code, but the conn.Dispose() line will execute even if the catch block throws an exception. Also, you can have a finally with no catch. It's common to use this in a method that changes a Windows cursor: this.Cursor = Cursor.Wait; try { // Do something time consuming here... } finally { this.Cursor = Cursor.Default; } In the above, you can have the cursor change back in the finally at the bottom. This is helpful if the code in the try block may exit early ("return;" in C#). If you have 3 or 4 exit points in the try block, you don't want to have to reset the Cursor each time. -Nerseus
  23. Yes, yes... a much simpler solution! First though - you can't modify a collection while inside a foreach loop - so says the MS help. That would include deleting items from the collection, adding items are reassigning the "pointer" to a new object. To delete rows from a collection, just loop backwards in a for loop: for(int i=dsMyDataSet.MyTable.Rows.Count-1; i>=0; i--) { if ( shouldbedeleted ) { dsMyDataSet.MyTable.Rows[i].Delete(); } } You can, and probably should, encapsulate this in a reusable function as it comes up fairly often. Passing in a filter string is probably a good idea as well. public static void DeleteRows(DataSet ds, string tableName, string filter) { DataRow[] rows = ds.Tables[tableName].Select(filter); for(int i=rows.Length-1; i>=0; i--) { if ( shouldbedeleted ) { rows[i].Delete(); } } } (You can add your own error checking and such) -Nerseus
  24. No, you can't bind directly to a string variable. If you have a class with a string property, you could bind to that string. You can bind to almost anything, other than a stand-alone value-type variable (such as a string, DateTime, int, etc.). You can even bind one textbox to another with something like: textBox2.DataBindings.Add("Text", textBox1, "Text"); -Nerseus
  25. My idea is to NOT do anything special. If the user has a slow connection and they see that email is being downloaded or checked, then why would they press a button that does something over their already overloaded network connection (such as downloading lookups or whatever it is your program is doing)? In summary, only the user will know when the connection is "busy", so why not let them decide when to take an action in your app? Now if your app is doing things behind the scenes with no user intervention, then you have a problem. If you really need to detect the network traffic to wait for a less busy time, I can't help. On the surface, it just seems like a hard way to tackle a problem... -Nerseus
×
×
  • Create New...