Heath Stewart wrote: Keep in mind, however, that most databases (Oracle is the only major database I can think of that can hold an array, IIRC) can't hold arrays. So, in Access, MS SQL Server/MSDE, MySQL, etc., this would only be a string. So should it be in your DataSet (well, in most cases). Your caller should be responsibe for serializing and deserializing that string to/from a float[], from a logical perspective. Your right. This is probably a better way to go. Thanks for your insight on this. -- James --
james cxx
Posts
-
Parse Custom XML type into DataSet -
Parse Custom XML type into DataSetSuppose I have a custom type made of a list of floats, and I want to represent it compactly in XML like this: [2.718, 3.142, 1.613, 1.000] Suppose also that I have a dataset, with a datatable where one of the columns uses MyType, which is a essentailly a float[]. My question is this: How do I ensure the tag is written into this format and read properly back into the float[] when I use ds.WriteXml and ds.ReadXml mehtods? Is there an interface or something I implement in my custom type to write on the contents for the tag and also to parse it back in? -- James --
-
Controlling file permissionsThanks Russell. That's the ticket. -- James --
-
Controlling file permissionsAnyone have a suggestion on how I can manipulate file permissions? I'm referring to what you find if you right-click a file and choose Properties, and then the Security tab. I'd like to programmatically set the groups and names, etc., but I'm not seeing a way to access this. :wtf: -- James --
-
SharePoint Triggers?Is anyone out there familiar with SharePoint development? Is it possible to intercept actions, such as user clicking "New.." and then take some action, such as launch an external app to do some work. -- James --
-
XML round trip problemsHere's a simplified example. It creates an Xml file named "XmlRoundTrip.xml" on the Desktop from a DataSet and then Reads it back in. Just add the code below to the constructor of a default Form template and run it. The first Message box shows "Type written: System.Drawing.Point". The dataset is then cleared and the data is re-read. But the second Message box shows "Type read: System.String". Any ideas? Am I expecting too much from the DS XML methods?
// Create a DataSet DataSet ds = new DataSet("MyDataSet"); // Create a Table for the DataSet DataTable dt = ds.Tables.Add("MyDataTable"); // Definte two columns for the DataTable DataColumn dcA = new DataColumn("PointColumn", typeof(Point)); dcA.DefaultValue = new Point(8, 13); DataColumn dcB = new DataColumn("SizeColumn", typeof(Size)); dcB.DefaultValue = new Size(21, 34); // Add the columns to the DataDable dt.Columns.Add(dcA); dt.Columns.Add(dcB); // Create a new row with default values and add it to the table DataRow dr = dt.NewRow(); dt.Rows.Add(dr); // Build file name for Xml file. string myTempFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); string myXmlFilename = myTempFolder + "\\XmlRoundTrip.xml"; // Write the Xml file. ds.WriteXml(myXmlFilename, XmlWriteMode.WriteSchema); // Confirm the type of the first column. MessageBox.Show("Type written: " + dt.Rows[0]["PointColumn"].GetType().ToString()); // Clear the table dt.Clear(); // Read the data from the Xml file. ds.ReadXml(myXmlFilename, XmlReadMode.ReadSchema); // Inspect read type. MessageBox.Show("Type read: " + dt.Rows[0]["PointColumn"].GetType().ToString());
-- James -- -
XML round trip problemsI'm writing out a dataset...
dsPrefs.WriteXml(ManagerPrefsFilename, XmlWriteMode.WriteSchema);
and, at other times reading it in...dsPrefs.ReadXml(ManagerPrefsFilename,XmlReadMode.IgnoreSchema);
The problem is that one of the columns is of type Point. The XML written by .WriteXml seems to contain all the info needed to describe this. Yet when I read it back in with .ReadXml and check the type it is System.String. I've tried different XmlReadMode to no avail. Any idea why these aren't being converted to the correct type when read in? -- James -- -
SqlDataAdapter.Update sometimes does not updateSo I'm happy to report the problem was with my code and not with the .NET SqlDataAdapter. But I think the circumstances of the problem bear repeating so that others might avoid it. Form A creates some SqlDataAdapters that fill a dataset and periodically refreshes it. At some point, due to user interaction, an instance of "Form B" is created and passed a reference to the SqlDataAdapters. Form B then finds a DataRow in one of the tables of the dataset, does some work on it, and then calls SqlDataAdapter.Update to put the changed DataRow in the database. And this worked _most_ of the time, but occasionally it would not - no data would be updated to the database. It turns out that during Form A's periodic update, it would clear the datatable and the refill it. This process would cause Form B's datarow it was working on to get to a state of DataRowState.Detached. Since the DataRow was now detached, when form B would call SqlDataAdapter.Update, the info from the row would not go to the database because the DataRow is not associated with the DataSet that the adapter was working with. And there was no error to be reported in this circumstance. So the moral of the story is this: Beware what's happening to your DataSet or DataTables while working with a DataRow. And it doesn't hurt to make sure the row hasn't somehow become detatched when you weren't watching. -- James --
-
SqlDataAdapter.Update sometimes does not updateAs the subject suggests, I'm simply updating the database with SqlDataAdapter.Update and sometimes no update occurs, but usually it does. If it never worked, I'd know it was a problem with my code, but running twice the same steps doesn't always produce the same results. I've read on the web that others have seen this behavior but haven't seen any fix or workaround. Anyone here experienced this or know a workaround? -- James --
-
Which NUD called this MenuItem?So I kept working on it and discovered the following: The NumericUpDown is a contol composed of other controls. If the user pulls up the context menu by right-clicking the TextBox area of the NumericUpDown, the the ContextMenu's SourceControl can be cast to a TextBox, or you can get the parent of the TextBox which will be the NumericUpDown I was originally seeking. If the user right-clicks the spinner portion, the ContextMenu's SourceContol is the NumericUpDown directly. So the code that does what I was asking is here:
private void miProg010_Click(object sender, System.EventArgs e) { MenuItem mi = (MenuItem) sender; ContextMenu cm = mi.GetContextMenu(); NumericUpDown nud = null; if (cm.SourceControl.GetType() != typeof(System.Windows.Forms.NumericUpDown)) nud = (NumericUpDown) cm.SourceControl.Parent; else nud = (NumericUpDown) cm.SourceControl; nud.Value = 10; }
Hopefully this saves someone out there some grief. -- James -- -
Which NUD called this MenuItem?I have a ContextMenu with about a dozen MenuItems in it. I've assigned the ContextMenu property of several NumericUpDown controls. When the user right-clicks one of the NumericUpDown controls and then selects a MenuItem from the ContextMenu. This triggers the MenuItem's Click event. Within the MenuItem's event handler, I need to determine which NumericUpDown control called the MenuItem so I can set the Value property of the NumericUpDown to the appropriate value. The problem is, I cannot seem to make this happen. The SourceControl of the ContextMenu has a type of "UpDownBase+UpDownEdit". I've found UpDownBase in the docs, but I get casting errors whenever I try to get to the value of the NumericUpDown. Such as...
private void miProg010_Click(object sender, System.EventArgs e) { MenuItem mi = (MenuItem) sender; ContextMenu cm = mi.GetContextMenu(); Control c = (Control) cm.SourceControl; UpDownBase udb = (UpDownBase) c; }
Any ideas? -- James -- -
DataGrid binding issuesI'm working with the windows forms DataGrid and running into some problems. The DataGrid is bound to a DataView derived from a Dataset, filled by a SqlDataAdapter. I encounter two problems when I call SqlDataAdapter.Fill(dataSet, "Table"): 1) The DataGrid re-sorts based on the first column. 2) If the user had resized any rows, those rows are set back to the default size. Basically, I don't want the appearance of the grid to change when I call Fill(). Is this possible, or do I need to manually manipulate the a dataset. -- James --
-
Trouble removing deleted rows...Calling AcceptChanges on the datatable after the Fill did not seem to remove the extra records. However, calling Clear on the table just before calling Fill does the trick. I was a little wary of using Clear for fear of deleting my database, but I see it only clears the table and doesn't mark records for deletion. Thanks for the help! -- James --
-
Simple way to start a process?I'm looking for a simple way to lauch Windows Explorer from C# and have it open up to a given folder. What I DONT want is to have a black command prompt window to flash up on the screen briefly while it executes a command line (I really hate that, and it confuses users). I've looked through some WMI articles, but they seem overly complex for what I'm trying to do. Any suggestions? -- James --
-
Trouble removing deleted rows...I have a DataSet that is filled by a SqlDataAdapter. If a row is deleted within the app, this is properly reflected in both the DataSet and central database when Update() is called on the SqlDataAdapter. However, if records are deleted from the database by some other process (outside the application), and I subsequently call the Fill(dataset.table) method of the SqlDataAdapter, the rows that were deleted from the database still seem to exist in the DataSet. Any ideas how I can ensure that if records have been deleted from the database, that these deletions are fully reflected in the DataSet? -- James --
-
DataGrid alterations...Thanks AW and Braulio for the ideas. I'll explore these. -- James --
-
DataGrid alterations...I have a DataGrid bound to source. The source table has a column that contains status numbers (integers), and the dataGrid shows these numbers. I have another table in the database which associates these numbers with a string. Does anyone know of a way I can make the dataGrid show the associated string (from the other table) instead of the numbers in the current table? -- James --
-
More than one table in DataSetTry it once with the IDE/Form Designer first: drag a dataAdapter to the form and configure it. Such as "SELECT * FROM Projects". drag another dataAdapter to the form and configure it. Such as "SELECT * FROM People". Now right-click the first dataAdapter icon and choose Generate Dataset. In the form that pops-up choose New Dataset, and name the dataset something like DSAll. This is actually the schema name, but a dataset will be created, named like dsAll1. Now right-click the "other" dataAdpater and choose Generate Dataset. This time, choose "Existing Dataset" and select the dataset you just created. Then you have two dataAdapters (one for each table) which both update data in a single dataset (which contains two tables). You can then look over the Designer generated code to see what it did.
-
New to C#parths, C# Essentials from O'Reilly for $25 bucks is well worth it. It's thorough for a small book, provides concise descriptions, and has lots of small examples. -- James --
-
Constrain form to horizontal resize only?Thanks Jim Stewart and peenu for the help! :-D I see there are a lot of properties I overlooked. The MaximumSize and MinimumSize properties did the trick: this.MinimumSize = new Size (400,400); this.MaximumSize = new Size (1280,400); -- James --