Jump to content
Xtreme .Net Talk

Nerseus

*Experts*
  • Posts

    2607
  • Joined

  • Last visited

Everything posted by Nerseus

  1. To hog: The SqlException is for use with the SqlClient namespace (for SQL Server). For the OleDb there's an OleDbException object. -Nerseus
  2. For the record, you can use a column in a where clause without including it in the select. So you could do: SELECT FirstName, LastName FROM Users WHERE UserName = 'dan' But, sometimes you need extra columns (especially for joining tables that are stored separately in the DataSet and used for DataRelations) and then you just have to hide them. And at least you provided some code, Robby. I was too lazy to clean up my own sample code :) -Nerseus
  3. I can't imagine that code actually works, hog. It's pretty much what MarkItZero first had. You can't do the CStr on the null value to test if it's Null :) Sorry about the bad syntax, MarkItZero. I'm a C# guy and we use "==" to compare values. I didn't realize VB.NET wanted to use Is to compare objects. Glad you got it working! It's too bad VB.NET doesn't support the same type of IIf as C#, which short-circuits the "if" logic. So you can use: text = (row("col")==System.DBNull.Value ? String.Empty : row("col").ToString()); In other words, evaluate the expression and if it's true, only run the TRUE part. In VB's IIf, both the True and False part are always evaluated, which stinks for doing simple checks like the one you want. -Nerseus
  4. Check out the DataGridTableStyle object. You can exclude columns through that (a grid has a default one, I think, but I can't remember the property name that exposes it). When you create a new DataGridTextBoxColumn object, you can specify it's Format property. Something like "c" should give you currency in the local machine format. -Nerseus
  5. Yes, you will have to have a working version of IE on a machine that uses the WebBrowser control. -Nerseus
  6. You can't do this (that I know of) directly. The easiest solution would be to add an expression column to your Order table (I would assume that's the one that has the MemberID and you want to display Member Name). The expression column would get the Member Name from the Member table. Assuming you have a relationship set up between the two tables in your DataSet, the expression would be very simple, something like "Child(OrderMember.MemberName)", depending on your column and relationship names. There are trickier options of course. One involves developing your own (or buying) a combobox type of control. You can bind it to the MemberID and have it show the text of the Member Name from the Members table. Another option is to use Microsoft's unsupported JoinView class that basically creates a SQL Server like "view" of data. Similar to a DataView, only it joins multiple tables into one bindable class. Search MSDN for JoinView for the VB.NET sourcecode. -Ner
  7. I'm sure your previous method involved hooking the window and finding the right window handle. You can do the same thing in .NET - you'll just have to import the DLL calls. Having said that, I hope you're not trying to get around any type of software restriction with this code. I'm sure whoever disabled the button had a good reason, right? :) -Nerseus
  8. The IIF function evaluates ALL parts of the expression. Meaning, it will try the CStr on the column even if it's null. Regardless of that, your code is ALWAYS trying the CStr() on the column, which is bad. If you split out the If everything will be fine. You can easily write a wrapper for the following lines of code as well, if you use them often: If RcrdSt("Location") = System.DBNull.Value Then txtLocation.Text = String.Empty Else txtLocation.Text = RcrdSt("Location").ToString() End If I also got rid of your use of CStr, which is a backwards compatable feature for old VB users. The new and "better" way is to use the ToString method (available on every object). -Nerseus
  9. I don't think you really understand Robby's question. Since no one is going to write the program for you, we just need to know if you need help with: A. Writing the SQL to retreive the right records B. Setting up a database connection (connection string, the objects involved, etc.) C. Binding the listbox to the DataSet or results from a DataReader There are a number of steps to connect to a database and show the results - we're not sure of your level of experience and no one wants to write up 200 lines of sample code if you only need 3 :) -Nerseus
  10. In my experience it's always best to be explicit with SQL, never use the shortcuts. That includes putting brackets on all column names, never using table.* in a select list, and always explicitly naming the columns in an INSERT (instead of "INSERT INTO table1 VALUES ..." use "INSERT INTO Table1 (col1,...) VALUES ..."). Just my opinion, but it usually saves trouble (for future reference). -Nerseus
  11. Here's one method (there are a number of options): // Get filtered list of rows DataRow[] newRows = origDataSet.Tables["Table1"].Select("ID < 5"); // Copy the dataset's structure, not the data DataSet newDataSet = origDataSet.Clone(); // Copy each filtered row to the new dataset foreach(DataRow row in newRows) newDataSet.Tables["Table1"].ImportRow(row); -Nerseus
  12. Also check what columns Access is showing. Since you're using "tblJobs.*", I can't see what those columns are. If any have the same name as the other columns in your select, then that might cause a problem as I don't think you can have two of the same named columns in one select. Access will allow that, but ADO.NET won't. For example, if tblJobs has a "name" column then that might be the problem. If the columns are all unique, I'd try simplifying the query one bit at a time until you figure it out. For example, try this query in VB.NET: Select tblJobs.* FROM tblJobs WHERE tblJobs.jobdone=0 If that works, then add one more table, then one more, then the final table. Hopefully you can figure it out doing it that way (if even the simple query works). -Ner
  13. For now you can just catch a generic Exception object. Use MsgBox to show e.Message (assuming you call your Exception variable e). You can also trap for SqlException, but the generic one will probably be fine for now. You might be able to use the @@IDENTITY later, I can't recall offhand. I know that you generally don't WANT to, since it's another round trip for something that you could easily get during your first call. -Nerseus
  14. Well, I'm not sure why you have a global array. Maybe you want your global version of the Record variable to NOT be an array? Only YOU can answer that :) If you do change the global reference to NOT be an array, I'd delete all your local instances since I'm pretty sure that's not what you want. -Ner
  15. What's the error message? Also, you can't execute "SELECT @@IDENTITY" AFTER you run the INSERT, you need to keep them together (I'm almost positive but not 100%). But I'd get the INSERT working first :) -Nerseus
  16. I'll try to answer it before it's asked :) If myReader("description") = System.DBNull.Value Then ListView1.Items(i).SubItems.Add(string.Empty) Else ListView1.Items(i).SubItems.Add(myReader("description").ToString()) End If Of course, if the description is null, you may not want to add it at all. I'm just showing how you could detect null and add an empty string instead. By the way, that code may not compile - I typed it by hand (not in the IDE) but it should be close -Nerseus
  17. Your global definition is: Public Record(30) As Members your local definition is: Dim Record As Members Your code is using: Record.Jt = txtJt.Text which means it's using the local Record variable, not the global one. If you delete the local variable, you'd have to change your code to: Record(0).Jt = txtJt.Text Or use whatever index you want instead of 0 (zero). The code you posted only shows how you're filling the structure. I'm not sure how you're doing the saving, so it's impossible to say why one form would save and another would not. -Nerseus
  18. Remember that every column in a DataSet/DataReader is an object. That object can be pretty much any type. Luckily, all objects have the ToString() method. If your column might be NULL (NULL in your database, System.DBNull.Value in code), you may want to trap for that and use "string.Empty" instead of column.ToString(). -Nerseus
  19. You can wrap them in CDATA, as in: ...xml snippet: <Text><![CDATA[<iframe]]></Text> That way you can put just about anything you want between "<![CDATA[" and "]]>". You can also parse certain strings to make them compatable. For example: ...xml snippet: <Text><iframe</Text> -Nerseus
  20. Well audit operations will want to return data that was affected. You could use the Read method but you may want to know how many records were affected before you start looping. Don't forget that INSERT, UPDATE, and DELETE can affect multiple records or even all records (if there's no WHERE clause). If you're writing auditing/logging code, you may want to write out the rows affected to a parent log table, and the details of what was affected to a child table. You'd have to know the rows affected to write the parent record first, then write out the details and associate them to the parent ID. That's just one way to use it - I'm sure others have found a use for it as well. :) Now, make those squirmy eye quit twitching, I can't think straight! :p -Nerseus
  21. I'm confused about your variable Record. You have a global one declared as an array, and another one declared in each form? -Nerseus
  22. Try this: ListView1.Items(i).SubItems.Add(myReader("description").ToString()) -Nerseus
  23. How are you storing your images? As pictureboxes, one picturebox and one file just loaded from disk? Let's assume you have a picturebox with a picture of some kind and you want to load a gif and copy that gif on top of the picture in the PictureBox. The general idea is to load the gif into a Bitmap object and paint it onto the picturebox. You can create a bitmap with (C#): Bitmap b = new Bitmap(@"c:\temp\bitmap1.bmp"); You'll also need a Graphics object that's associated to your picturebox. The Graphics object handles the drawing: Graphics g = pictureBox1.CreateGraphics(); Now you can use g.DrawImage(b,...); to handle the drawing. There are 30 overloads for DrawImage, most handle drawing portions of the bitmap to a portion of the picturebox (to handle scaling, cropping, etc.). If you want to rapidly draw a gif onto a picturebox, for a game for instance, then you will find lots of samples. Search google for DrawImage and Bitmap and C# or whatever your favorite language is. -Nerseus
  24. If you're writing the code to flood fill an arbitrary chunk of bits (such as allowing the user to draw an enclosed area and then fill it or fill an area on a pre-loaded bitmap), you'll have to code the FloodFill yourself. If you know the exact dimensions of the area (such as on an object that you're creating through code - such as a pentagon, rectangle, or any arbitrary closed path), then the Graphics object can draw a solid object filled as well as an outline. -Nerseus
  25. Nerseus

    Speed up

    Some programs, such as WinAmp, are coded to take up more CPU power than other programs. This may cause a jittering. Also, if you're doing animation based on a regular timer, the API timeGetTime, or the Environment.TickCount, keep in mind that they have about 20ms accuracy. I had a Ms Pacman clone that ran choppy because of this - I changed it to use QueryPerformanceCounter and all was better. It was only because my machine was running TOO fast that I saw the stuttering (my old 486/VB5 version used timeGetTime without any problems). -Nerseus
×
×
  • Create New...