
Gladimir
Avatar/Signature-
Posts
60 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by Gladimir
-
Select method works for String, not DateTime.ToString?
Gladimir replied to Gladimir's topic in Database / XML / Reporting
I'm not quite up to speed on all this stuff. Parameters? I use parameters in SQL statements all the time, but I'm not familiar with using them for DataColumn Expressions. Further explanation would be greatly appreciated. -
Select method works for String, not DateTime.ToString?
Gladimir replied to Gladimir's topic in Database / XML / Reporting
I did forget to mention that I was using the pound sign (#) around my date-time as recommended in the DataColumn Expression reference. I will check the regional settings and write a quick stand-alone test case and let you know what I find. I can tell you that the exprDate string would always properly append the lastFileDate string, which would always match the LastModified DateTime value, even in cases where the formatting was different from computer to computer. I tend to think it is not related to formatting because the DataTable.Compute method returns the exact date and time I am going to use to find the file with that exact date and time. Whatever format is returned by the Compute method is the format I use in my Expression. Anyway, I will keep you all posted in this thread. Thanks for the suggestions and the help. I like the 'typeof' tip, very smart. -
I use the DataTable Select method to get find the most recent "LastModified" date in a table of similarly named files. I then use the resulting date and time to get the specific filename and path from the same DataTable. The problem is that this worked fine on my Windows XP machine, but did not work on any of several Windows 2000 computers at the client's location. The Select method would always return 0 (zero) rows even though we were working with the exact same list of files in both locations. As part of some experimentation, I changed the Type of the "LastModified" from "System.DateTime" to "System.String" and everything began working as expected at the client's location. If anyone has any clue as to why I cannot use the "System.DateTime" DataColumn type in the client's Windows 2000 environment when it works perfectly in my Windows XP environment; I would greatly appreciate any input. Here are the relevant code snippets, starting with the DataTable definition: DataTable fileinfo = [color=Blue]new[/color] DataTable("TestFileInfo"); fileinfo.Columns.Add("FileName", Type.GetType("System.String")); fileinfo.Columns.Add("FileSize", Type.GetType("System.UInt64")); [color=Green]/* DEBUG BEGIN: The following line does not work in client environment... fileinfo.Columns.Add("LastModified", Type.GetType("System.DateTime")); */[/color] fileinfo.Columns.Add("LastModified", Type.GetType("System.String")); [color=Green]/* DEBUG END */[/color] fileinfo.Columns.Add("FullPath", Type.GetType("System.String")); And now the logic that performs the lookup using the Select method: [color=Blue]string[/color] exprFile = "FileName LIKE '" + pattern + "*'"; [color=Blue]string[/color] latestFileDate = dtFiles.Compute("MAX(LastModified)", exprFile).ToString(); [color=Blue]string[/color] exprDate = exprFile + " AND LastModified = '" + latestFileDate + "'"; DataRow[] foundRows = dtFiles.Select(exprDate); [color=Blue]string[/color] latestFile = null; [color=Blue]if[/color] (foundRows.Length > 0) latestFile = foundRows[0]["FullPath"].ToString(); [color=Blue]return[/color] latestFile; The above code returns 0 (zero) rows if "LastModified" DataColumn type set to System.DateTime. Any help, suggestions, or even wild guesses would be greatly appreciated.
-
I think you can just use the DataGrid.Select method in the CurrentCellChanged event. For example: [color=Blue]private void[/color] dataGrid1_CurrentCellChanged([color=Blue]object[/color] sender, System.EventArgs e) { [color=Blue]int[/color] rowIndex = dataGrid1.CurrentRowIndex; dataGrid1.Select(rowIndex); }
-
Hi Charlie, As PlausiblyDamp mentioned, it is trivial to loop through all the controls of a form and identify them by type or name. Here is some code: [color=Blue]int[/color] labelCount = 0; [color=Blue]for[/color] ([color=Blue]int[/color] i = 0; i < [color=Blue]this[/color].Controls.Count; i++) [color=Blue]if[/color] ([color=Blue]this[/color].Controls[i].GetType().ToString().EndsWith("Label")) labelCount++; label1.Text = labelCount.ToString(); I used Label1 just to give me a label to count. I hope this helps.
-
I don't think it is as easy as it used to be in VB6. I've never needed a control array in .NET; so I've never done it, but here is an article from Microsoft. Creating Control Arrays in Visual Basic .NET and Visual C# .NET
-
I don't think so. I believe what you are obseving is the cost of the .NET CLR.
-
-
The code is C#, but the objects will be the same for VB. I don't know what the VB equivalent to the using keyword (maybe Inherits) but you'll need these libraries for an Access database. These statements belong at the top of your code file with the other similar statements. using System.Data; using System.Data.OleDb; Now let's define the steps and create a connection object for our MS Access database and create our database connection object. [color=Green]/* Three steps to a database connection: * 1. Create a database connection object for our MS Access database. * 2. Create a data adapter object for our connection object. * 3. Create a command object for our data adapter object.*/ /* Step 1: A database connection object is a .NET connection class and a * connection string. See [url=http://www.connectionstrings.com/]Connection Strings[/url] for more.*/[/color] [color=Blue]string[/color] mdbstr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\temp\northwind.mdb;"; OleDbConnection mdbConnx = [color=Blue]new[/color] OleDbConnection(); Now, we'll use the connection object in the creation of our data adapter. The data adapter is not always necessary. Depending on what we're trying to do, we could just use a connection object and a command object, but we'll be using the CommandBuilder in this example, which requires an adapter. [color=Green]/* Step 2: A typical data adapter is a .NET data adapter, an SQL statement, * and an instance of a .NET database connection object.*/[/color] [color=Blue]string[/color] strSelect = "SELECT * FROM Customers WHERE (Region Is Null)"; OleDbDataAdapter mdbCustomers = [color=Blue]new[/color] OleDbDataAdapter(strSelect, mdbConnx); At this point, we're actually ready to read records from the database table and start using them in our application, but we'll go ahead and define a command object while we're here. The OleDbCommandBuilder object automatically creates the SQL statements necessary to update a single table from a DataSet, through a data adapter. As with anything that is done "automatically", the OleDbCommandBuilder is not infallible, but it is pretty reliable and I have often used it. [color=Green]/* Step 3: create an OleDbCommandBuilder object to automatically generate SQL * statements for single-table updates if you set the SelectCommand property * of the OleDbDataAdapter.*/[/color] OleDbCommandBuilder custCommands = [color=Blue]new[/color] OleDbCommandBuilder(mdbCustomers); Now let's use these objects in our application. First, we will declare and populate a DataSet, a collection of database tables. We will have only one table in our collection. [color=Green]/* Create a dataset and populate it using the data adapter object. */[/color] [color=Blue]string[/color] dsName = "dsNorthwind"; [color=Blue]string[/color] tableName = "Customers"; DataSet ds1 = [color=Blue]new[/color] DataSet(dsName); [color=Blue]try[/color] { mdbCustomers.Fill(ds1, tableName); } [color=Blue]finally[/color] { mdbConnx.Close(); } Now, throw a DataGrid, a ListBox, and a ComboBox on a windows form and bind them to appropriate elements in our dataset. [color=Green]/* Bind the data in our dataset to our data aware controls.*/[/color] DataTable dt = ds1.Tables[tableName]; dataGrid1.DataSource = dt; comboBox1.DataSource = dt; comboBox1.DisplayMember = dt.Columns["CompanyName"].ColumnName; listBox1.DataSource = dt; listBox1.DisplayMember = dt.Columns["ContactName"].ColumnName; The great part about all of this is coming. Select the drop-down from your ComboBox, scroll all the way down and select the last company name. You'll see the contact name automatically selected in your ListBox and the DataGrid will automatically move the selection caret to the record matching that company name! Brilliant! When you're ready to update, simply call the Update method of the data adapter object, just as you used the Fill method. [color=Green]/* This code will not work without an instance of the OleDbCommandBuilder object. */[/color] [color=Blue]try[/color] { mdbCustomers.Update(ds1, tableName); } [color=Blue]finally[/color] { mdbConnx.Close(); } And you're on your way...
-
Unfortunately, I can offer advice as I am only feeling my way around these areas, but you need to use delegates and events. Basically, you will create a custom EventHandler and custom event in your windows process class and use that in your console application. Like I said, I am just feeling my way around these areas myself, but I can provide some links that should get you well on your way. Most of these are C# oreinted. Microsoft: Events and Delegates Code Project: Events and Delegates simplified Google Search: C# Delegates Events Classes Sorry that I could not be more help and provide an actual code example.
-
Actually, that code doesn't even build. So, that answers my question as to it's appropriateness.
-
TableStyles TableStyles was exactly the problem. The more work I do on this custom datagrid, the deeper the water. Now I am beginning to question what code is appropriate in a windows control library and what should remain on the user-interface (Form1). Here is my code to disable the sorting: public class CustomGrid : System.Windows.Forms.DataGrid { private System.ComponentModel.Container components = null; [color=Blue]private[/color] CurrencyManager cm = (CurrencyManager) [color=Blue]this[/color].BindingContext|[color=Blue]this[/color].DataSource|; [color=Blue]private[/color] DataGridTableStyle dgts = [color=Blue]new[/color] DataGridTableStyle(cm); private ArrayList _selectedColumns; public CustomGrid() { InitializeComponent(); [color=Blue]this[/color].dgts.AllowSorting = [color=Blue]false[/color]; _selectedColumns = new ArrayList(); } } This control uses ColumnStyles to paint the selected columns. Therefore, this custom control will always use TableStyles and a CurrencyManager. I want this control to self-contain all the code needed for the core functionality of column-selection. The CustomColumnStyle is actually part of the class in the same namespace, but is not a nested class in the CustomGrid.
-
Disabling DataGrid Sorting & Project Rebuilding... I'm having one last problem and rebuilding doesn't seem to be handling the changes. My custom datagrid allows the user to select columns. However, when the user Left-Clicks the column header, the column is selected as desired, but it is also Sorted; an undesired effect. So, I modified my CustomGrid class project like so: public class CustomGrid : System.Windows.Forms.DataGrid { private System.ComponentModel.Container components = null; private ArrayList _selectedColumns; public CustomGrid() { InitializeComponent(); [color=Blue]this[/color].AllowSorting = [color=Blue]false[/color]; _selectedColumns = new ArrayList(); } } I selected Rebuild from the Build menu in my CustomGrid project, then selected Rebuild from the Build menu of my TestWindowsApplication, but the sorting still occurs. Any help would be greatly appreciated.
-
Thanks! That worked! Regarding your word of warning, after making changes and rebuilding my custom control, do I simply remove the Reference from my Windows Application and re-add the Reference to get the new changes? Thanks again.
-
I have a solution with two projects. The main project is a Windows Forms Application and the second project is a Windows Control Library. The goal is to use the custom datagrid created in the windows Control Library in the Windows Forms Application and have it show up in the Toolbox for that project. In the Windows Control Library project, I have declared my derived DataGrid, created some properties, and overridden the OnMouseDown event. Here is my class declaration: public class CymiGrid : System.Windows.Forms.DataGrid My new CymiGrid builds without error, but I'm unsure of the next step. I have added it to the Windows Application as a Projects Reference, but that doesn't get it in the Toolbox. I haven't used any objects from the Toolbox in my custom Control Library, not even a DataGrid. Is that what I need to do? Any help is greatly appreciated.
-
I have a series of XML files with accompanying DTD files. If I just use the Excel Data-XML-Import menu to load the files, the first file fails due to invalid characters ('<') and the second file completes with errors (truncation). I asssume that I need to write a custom XML parser to handle these invalid characters and large amounts of data in a single field. I am proficient with Visual Basic 6, VBA, and C#. I have Visual Studio .NET 2003. What is the best way to get started? Any suggestions or links to good sites with explanations and/or sample code would be greatly appreciated.
-
A Workaround? I know this is not really an answer, but one possible workaround might be to set the Height and Width properties to your pre-defined size in the Resize event. It's not perfect, but at least the Form will always "snap" back to the desired size until you get a real answer.
-
Importing and Using an ActiveX Control...
Gladimir replied to Gladimir's topic in Interoperation / Office Integration
Thanks! I have actually managed to get that far and things seem to be working to some degree. Unfortunately, I may be having a problem with versioning in Visual Studio .NET 2003. Windows XP Explorer file Properties reports Windows/System32/Pdqcom32.ocx as version 3.21, which corresponds to the current patch level. The component listbox of the COM tab you mentioned reports my control as being Version 3.1, which corresponds to the pre-patched version. However, the trouble I am seeing may be completely unrelated to this. I would offer more information, but I am still investigating the issue and making sure I've dotted my T's and crossed my I's before posting another question. Basically, I set the "Emulation" property to a particular value from a drop-down list in the Properties box, but I get the following error message: Invalid property value. Method AppPdqcommLib.AxPDQComm[DISPID=-2147418105] not found. Now I recall a BAS module containing all the constants and such that accompanied this control. I am researching that to see if I need it in my C#/.NET app, and if so, how to import it as well. -
I want to use an old pdqcom32.ocx control in a Windows Forms project. I have sucessfully imported the control using aximp.exe and now have a few dll files and the C# source code for the wrapper. I have created a blank C# project in Visual Studio (2003) and added a Windows Form. What is the best way to go about actually using my control? I can add either the PdqcommLib.dll or the AxpdqcommLib.dll under References in the Solution Explorer, but I can find neither control in the .NET or COM tab of the Add/Remove Item dialog for the Toolbox. That's the main question here... Out of curiosity, I'd like to know more about the files created by aximp.exe. For example: 1. What is the difference between AxpdqcommLib.dll and PdqcommLib.dll? 2. What is the relationship of the StdType.dll created by aximp.exe to the other two dll files it created? 3. I know AxpdqcommLib.pdb is a program debug database, but what is its function? Does the file belong somewhere in particular? Is it optional?
-
Regex: how do you get to match __X__Y__ ?
Gladimir replied to pasu857's topic in Regular Expressions
Not understanding the question... I'm not quite catching the question. Are you capturing the 'Y' as well as the 'X' and 'X_x' matches with that expression? Or perhaps you are purposefully omitting the 'Y'? -
Possible problem with escape characters... You may want to consider putting the @ character in front of your path string: appAccess.OpenCurrentDatabase(@"\\<ip address>\database folder\DailyFloorOpps\AllStoresDB\DailyFloorOpps.mdb") This will prevent those back-slashes from being seen as special characters. I hope this helps.
-
SOLUTION... Thanks JABE! The LEFT OUTER JOIN did the trick. Here is what the final query looks like in the Access Query Designer if anyone is interested: SELECT REF_MasterNomen.Description, REF_CrossReference.Description, REF_CSDSoftware.ComputerName, REF_CSDComputers.LastUserID, REF_CSDUsers.Username, REF_CSDComputers.BusinessUnit, REF_CSDComputers.Department, REF_CSDComputers.SiteLocation, REF_CSDComputers.LastDate FROM (((REF_MasterNomen INNER JOIN REF_CrossReference ON REF_MasterNomen.NomenID = REF_CrossReference.NomenID) INNER JOIN REF_CSDSoftware ON REF_CrossReference.DescID = REF_CSDSoftware.DescID) INNER JOIN REF_CSDComputers ON REF_CSDSoftware.ComputerName = REF_CSDComputers.ComputerName) LEFT OUTER JOIN REF_CSDUsers ON REF_CSDComputers.LastUserID = REF_CSDUsers.userID WHERE (((REF_MasterNomen.NomenID)=14) AND ((REF_CrossReference.CategoryCode)=3) AND ((REF_CSDComputers.Billable)=Yes)) OR (((REF_MasterNomen.NomenID)=14) AND ((REF_CrossReference.CategoryCode)=3) AND ((REF_CSDComputers.Refreshed)=Yes));
-
Still a problem... I manually entered your additions and added the extra set of parentheses for the third INNER JOIN statement, and it truncated the output to 762 records. Thanks for your attempt. This is not really a show-stopper, but it is frustrating because having the username would be convenient and I believe it should be possible. Maybe this is a short-coming of Access...
-
I am listing various information about all instances of Adobe Photoshop installed in our network. My current query produces information about 816 unique instances of Adobe Photoshop, including the last user id logged on to the computer when available. However, when I try to list the User Name associated with that user id, all records with no user id are dropped, pairing my listing down to 762 records. The last user id is retrieved from the LastUserID field in the REF_CSDComputers table. I'm attempting to pull the user name form the Username field in the REF_CSDUsers table. The userID field in REF_CSDUsers is related to the LastUserID field in REF_CSDComputers. SELECT REF_MasterNomen.Description, REF_CrossReference.Description, REF_CSDSoftware.ComputerName, REF_CSDComputers.LastUserID FROM ((REF_MasterNomen INNER JOIN REF_CrossReference ON REF_MasterNomen.NomenID = REF_CrossReference.NomenID) INNER JOIN REF_CSDSoftware ON REF_CrossReference.DescID = REF_CSDSoftware.DescID) INNER JOIN REF_CSDComputers ON REF_CSDSoftware.ComputerName = REF_CSDComputers.ComputerName WHERE (((REF_MasterNomen.NomenID)=14) AND ((REF_CrossReference.CategoryCode)=3) AND ((REF_CSDComputers.Billable)=Yes)) OR (((REF_MasterNomen.NomenID)=14) AND ((REF_CrossReference.CategoryCode)=3) AND ((REF_CSDComputers.Refreshed)=Yes)); Where should I be putting REF_CSDComputers.LastUserID and REF_CSDUsers.Username to list Username where LastUserID matches REF_CSDUsers.userID, without excluding records where LastUserID is blank? Any help, comments, or suggestions are greatly appreciated.
-
Well, I didn't realize we were talking about two separate databases here; that changes everything. Here is the code for LookupDescID and InsertNewDescription: private int LookupDescID(string strDescription) { // initialize master data connection object dbMaster masterdb = new dbMaster(); OleDbConnection master = masterdb.m_master; if (strDescription.IndexOf("'") > 0) strDescription = strDescription.Replace("'", "''"); string strScalar = "SELECT DescID FROM REF_MasterDescription " + "WHERE (Description='" + strDescription + "')"; OleDbCommand cmdScalar = new OleDbCommand(strScalar, master); Object oDescID = null; try { master.Open(); oDescID = cmdScalar.ExecuteScalar(); } finally { master.Close(); } int DescID = 0; if (oDescID != null) { if (oDescID.EqualsDBNull.Value)) DescID = 0; else DescID = Convert.ToInt16(oDescID); } return DescID; } private void InsertNewDescription(string strDescription, CategoryCode eCode) { // initialize master data connection object dbMaster masterdb = new dbMaster(); OleDbConnection master = masterdb.m_master; if (strDescription.IndexOf("'") > 0) strDescription = strDescription.Replace("'", "''"); int intDescID = GetNextID(strDescription); ushort iCode = (ushort)eCode; string strInsert = "INSERT INTO REF_MasterDescription (DescID, Description, CategoryCode) " + "VALUES(" + intDescID.ToString() + ", '" + strDescription + "', " + iCode.ToString() + ")"; OleDbCommand cmdMasterDescription = new OleDbCommand(strInsert, master); try { master.Open(); cmdMasterDescription.ExecuteNonQuery(); } finally { master.Close(); } } I may not be following proper conventions or procedures, but I use the IF snippet from the previous post along with these functions in a routine that processes about 350,000 records. It seems to perform fairly well.