Nerseus
*Experts*-
Posts
2607 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by Nerseus
-
I would strongly suggest reading the MSDN help or getting a good book on interfaces (and object oriented technology in general). These forums are better suited to getting answers to specific questions. -nerseus
-
Offhand, you'll need a new function PrintDataView that accepts a DataView instead of a DataTable. Then loop through a DataRowView collection instead of the Rows. You might change your PrintTable to be more generic, but since it looks like test code I'd just use two functions. -nerseus
-
Even if you never plan on working in a team, I'd use some kind of source control system. I use one at work and at home, even on test projects. I can't count the number of times I'd be writing a test project, change a bunch of test code (just prototypes mostly) and wish I could get back to where I was an hour ago, two hours ago or a day ago. Often my test projects morph around, sometimes testing APIs, sometimes testing Math functions, etc. If you use Visual Studio, I'd see if any of the programs you're looking at integrate "easily" with it. For example, Visual SourceSafe (from MS) lets you right click a file and "check out", "check in", "compare versions" and more. -Nerseus
-
Enums are about 90% good, 10% bad. The "bad" comes when you want to use them as the underlying int value. You must use manual casting to get the int value out. This can pose problems when you want to return an enum from a WebService, for example. If you return the enum, then the auto-proxy that Visual Studio creates tries to recreate the enums for you. You can change the method to return an int, but then you have to cast back to the enum. All that's not too bad... The biggest issue I've seen is when putting an enum's int value into a DataSet. I use enums for Code Dependent values (database values that have code tied to the lookup int values), but when putting the value into a DataSet you have to beware (!) - the column will gladly accept the enum directly but when you try and use it, you'll get a runtime error if the code assumes the value is an int. This will happen whenever you use the DataAdapter to update a proc, for example. But by and large, an enum is just a related group of constants. Sometimes they're used too often - when a new set of subclasses would work better for instance. If you find you have a switch statement or series of "ifs" used more than once in code, there's a chance what you really want is a new set of objects rather than an enum. -nerseus
-
Also something to check: I see you use a "Connect()" call but no similar "Disconnect()". Generally things like Files, connections, etc. need to have an explicit "Close" or "Disconnect" method to free the resources manually. This would be in addition to using the Disposable pattern to do manual cleanup, if it's required. -ner
-
Lets try this again - XML Question
Nerseus replied to Lou Elston's topic in Database / XML / Reporting
As I said in the first post, I wasn't sure what you really wanted and what you have. A "request" can take on many meanings... Let's assume you have some DLL on a server that you need to "call" into - your request. The "normal" way in .NET is to use remoting or a web service. These are the two most common ways to make a server to server call (or client to server in most cases). Web services use SOAP to communicate. SOAP is just a protocol, like HTTP. A protocol being a standard way that servers might communicate. You *could* make a SOAP call yourself. Basically build up the correct XML and send it using some tools (MS provides a SOAP toolkit which uses COM components). If you use webservices, this is all done for you. If you know how to setup a website and .NET code, you're halfway there. You'll want to look at creating an ASMX page (a webpage that exposes methods of a class). From your Visual Studio project you can right click on "Web References" (just below References in your project) and select Add. There's obviously a lot more to all this than what I've got, but it should get you started. A good book on webservices might help a lot. Many used ones can be found on Amazon for $10 or less. Then there's always MSDN for some other info. -nerseus -
I don't think there's any problem with it. Take NUnit for example. -nerseus
-
Lets try this again - XML Question
Nerseus replied to Lou Elston's topic in Database / XML / Reporting
I'm guessing no one responded because your question makes me ask more questions :) First, what do you mean by sending "XML requests"? XML is just a specific way to format text, at it's core. There are certain standards that rely on XML, but XML doesn't really do anything by itself. For example, SQL Server can interpret XML as a table. If you're using SOAP, which is a protocol - a standard for sending messages, then the "SOAP request" is formatted as XML. A DataSet can be viewed as XML. As for working with XML as an object model in .NET, you will most often use the XmlDocument object, part of the System.Xml namespace. You could use MSXML2 but it would go through the COM wrapper. I hear its transforms are a lot faster, but there are issues (COM being one, security being another). There are other objects in the System.Xml namespace that you might use, depending on your needs. Also, questions like "I need help learning Xml" often go unanswered simply because most people would expect you to search google and look for tutorials first. The questions that get the best answers are those that ask specific questions. For instance, "Which object would/should I use to load an XML file from disk and work with it in such-and-such way?". -ner -
We use the same approach as Rick's office and it works great. I don't believe VSS has any web interface for checking things in/out. If you really wanted/need that, there's nothing stopping you from doing it yourself - VSS is programmable through COM objects. Not sure if the effort would be worth it though... -Nerseus
-
Typically you have to write your own function for this. The function is normally written with a Try/Catch that attempts the conversion. If it converts, the function returns true. If it doesn't, it returns false. Depending on the type of numeric you want to return true (whole numbers only, floats, "$" and "," chars), you'll have to pick the right conversion function. -nerseus
-
I may be off, but I thought that XML, like HTML, was "english" ASCII based. Meaning, you couldn't have those non-"standard" characters in there. I think they needed to be encoded inbetween CDATA blocks or converted to their numeric equivalent, such as "%27". Might be wrong though... -ner
-
Generally, each namespace is a separate folder and you have one class per file. There's no hard and fast rule though - it's up to you. If classes are VERY related it's generally a good idea to keep them together in the same file. You may also want them in the same file if they're very small. Personally, I like every class in its own file with a few, very rare exceptions. For namespaces, assume your project is in c:\projects\Stitch. There should be a folder named c:\projects\Stitch\Database and the DBResult.cs lives in this folder. If you create the folders in Visual Studio and then add a file, the new class will have it's namespace default to using the folder name as an added level to the namespace. -ner
-
I discussed some of the points you ask in this thread. In your first sample, "x.i = this.i;" will put a copy of this.i into x.i. Changing x.i after the assignment will only change the copy. This is because an int is a value type and is always copied. In your second example, if the DataBaseClass object takes that connection string that's passed in and creates another connection, then it would have it's own separate connection. Closing it, starting/commiting a transaction, are all done on that connection. Connections are classes so they're reference types - assigning a variable of that type to another variable only copies the pointer (both variables end up pointing to the same thing). -ner
-
Some "purists" say you should NEVER expose public fields (variables) - encapsulate everything in a property. I think that's generally a good idea but I have a few data-only classes that are just easier to code with public vars. I guess I'm no purist :) -nerseus
-
Actually, I think varchar stores the string "hi" as 2 + 4 bytes, not 2 + 1. It uses 4 bytes for the "pointer" as I recall. Not that big usually. Unless I have a "state code" (for the US) that I KNOW is only 2 chars, I rarely use char for much. The savings just isn't worth it in most cases. Even a Vehicle's VIN, which is normally 17, is subject to change based on vehicle type (at least for the one's I've seen). So even something as "standard" as that can have enough variation that using varchar has it's programming/maintenance advantages. Personally, I think char made more sense when disk space cost more. Unless you're storing hundreds of gig of data or approaching terabyte sizes, I don't think there's much use for char for *most* applications/tables. -ner
-
The short version: char ALWAYS has spaces at the end, to pad the full length. So a char(10) with the text "hi" will actually be "hi " when you get it out. You would HAVE to trim in the DataSet to remove the trailing spaces. varchar has whatever you put in it. If you define it as varchar(10) and put in "hi", you'll get out "hi". If you put in "hi " you'll get out "hi ". text holds a HUGE amount of data but has searching/filtering limitations. You can't do a lot of common string functions on text fields. SQL Server/MSDE also has other options you can set. One of them will always trim trailing spaces. So if you tried putting "hi " into a column it would trim to "hi". I can't remember if that's at the column or database level though - you'll have to check the help. -nerseus
-
You could say "SELECT TOP 1 ...". I'm not sure if that's what the LIMIT thing does... -Nerseus
-
You can overload assignment though it's syntax isn't quite the same - you don't overload the "=" operator. Here's a sample for how to do it: public static implicit operator MyResultType(DataReader op) { return new MyResultType(op); } This allows assigning a variable of tyep MyResultType to a variable of type DataReader. In my sample, I assume you have a constructor on MyResultType that takes a DataReader and does something useful with it. You can replace implicit with explicit if you need to. Check the help on more info. -Nerseus
-
Do you mean you saved the DataSet as XML and reloaded it? Make sure you specifiy to save the schema. DBNull values are represented in XML by NOT being there :) -Nerseus
-
If you know how to query the table, you're almost done... if you don't, then ask how to write the code to query a table. If you can guarantee that the IDs in your table are 100% in order with no gaps, then you can use pure client side code to randomly pick 20 numbers (make sure you don't have duplicates). Then comma separate those numbers and build up a SQL string like this: "SELECT * FROM tblQBank WHERE QID IN (" + ids + ")" So if ids is a string that looks like "1, 56, 1054, 8763, 456, 23" then the SQL becomes: SELECT * FROM tblQBank WHERE QID IN (1, 56, 1054, 8763, 456, 23) If you can't guarantee the ID column will be sequential with NO gaps, then you'll need another approach. Here's a nice one (pseudo sql server code): CREATE TABLE #IDList ([id] int) SELECT qID INTO #AllIDs FROM tblQBank SET @i = 0 WHILE @i < 20 BEGIN -- Change the 0 below to use something more random SET @rnd = RAND(0) SELECT @Value = at position @rnd FROM #AllIDs -- Check if @Value exists in #IDList IF <doesn't exist> BEGIN -- Insert @Value INSERT INTO #IDList SELECT @Value SET @i = @i + 1 END END -Nerseus
-
In SQL Server you can use something like "SELECT getdate() AS [MyCoolDateColumn]". -Nerseus
-
Not sure if this will help, but just found this site. Might help with DirectX if you need it... By the way, you spelled Phoenix as "Pheonix" in your first post. Might distract those just reading the thread for the first time. -Nerseus
-
I can't speak for VB.NET, but I KNOW I've had "special" characters in C# - only when cutting and pasting. I found that if I cut and paste into notepad then copied from notepad right back to VS, it worked most of the time. Sometimes I had deleted the CRLF chars until two words were right next to each other (like eachother) and then manually typed a space and THEN pasted things back into VS. Every once in awhile it would be stubborn. In those cases, I just retyped the line. It should only "bite" you once. After that, you'll quickly learn to cut-n-paste to notepad or manually type a line. -ner
-
If you're using this for an API, most APIs return you the size of what was read. That would be what you'd use in the CopyMemory call. If you were to find a managed way to figure out the size of what myBuffer pointed to, I'm sure it would say 256 - the size of the array. It would never know the size of the data read in by the function. Your methods to determine the size is always 4 because they're all returning the amount of memory used by myBuffer. A pointer in current operating systems is 4 bytes (32 bit systems). While you could get the size of itText, you pretty much already know it. If the API is returning you text, you could convert the byte array to a string then use substring on Chr(0). Or, simply loop through each byte in itText until you find the value 0 - that should be the null terminator in C-style strings. -Nerseus
-
Solution #1 is very often used in conjunction with a modal popup. But whichever solution works best, that's what I'd go with :) -Nerseus