I have local datasets where I read using the following function. The obj.Read() simply executes a stored procedure which is a select statement. For some reason, for my only dataset where I have 3 tables, the "this.EnforceConstraints = true;" statements fails saying the constratints where not respected (and it seems to happen only in debug, I never had a complain from the staff using the runtime), but this is not true for three reasons : the database is a copy of what the runtime environement uses, it is intermitenet even if the database does not change and the database has the same relations as the local dataset. (see below for the relations) public void Read() { try { reading = true; this.EnforceConstraints = false; syncTime = DateTime.Now.ToUniversalTime(); foreach (SimpleObjects obj in this.Tables) { obj.Read(); } this.EnforceConstraints = true; reading = false; } catch (Exception e) { ....code..... } } Relations : (Very simple) Relations.Add(new DataRelation("MembersToMembersAssociations", Tables["Members"].Columns[0], Tables["MembersAssociations"].Columns[0])); Relations.Add(new DataRelation("MembersToMembersPhoneNumbers", Tables["Members"].Columns[0], Tables["MembersPhoneNumbers"].Columns[1])); This is very anoying for I am never sure if I delever a new version if the problem will affcet the runtime, Is it a bug in Visual Studio 2005 (version 8.0.50727)? Did anybody else encounter this problem ?
Johnny 0
Posts
-
Dataset disabling and reenabling constraints -
Binding with BindingSourceI have a strnge situation thta I just can't understand, any help or leads would be appreciated In my data layer I create BindingSource objects: public abstract class SimpleObjects : System.Data.DataTable { protected BindingSource binding = new BindingSource(); protected void Init() { sqlAdap.SelectCommand = selectCommand; sqlAdap.TableMappings.Add(tableMapping); sqlAdap.FillSchema(this, SchemaType.Mapped); binding.DataSource = this; } public BindingSource Binding { get { return binding; } } } I make the BindingSource (binding) object available as a property for all my SimpleObjects for forms to use. Wrks well in most cases but my problem is sometimes the binding goes berzerk when I add DataRows to certain SimpleObjects and it seems to happen when you add rows to child Tables. What happens most of the time is a DataGridView showing a child object will show a row in blue but if I ask the currently binded Object to the BindingSource, it returns me usually the first row. This definitelly happens only if a DataRow was added. Not sure What is happenning and not sure what to do. Any help would be greatly appreciated.
-
Using SqlFacet Attributes for an SQL functionHi, I wrote a function in C# to be used as a scalar function in SQL2005: [Microsoft.SqlServer.Server.SqlFunction(IsPrecise = true, IsDeterministic = true, DataAccess = DataAccessKind.Read)] public static SqlDecimal GetTaxAmountFromTax(SqlString tax, SqlDecimal amount) { SqlConnection conn = new SqlConnection("context connection=true"); SqlDataAdapter adap = new SqlDataAdapter("SELECT * FROM TransactionTaxes", conn); DataTable taxTable = new DataTable(); adap.Fill(taxTable); DataRow[] rows = taxTable.Select("[ID] = '" + tax.ToString() + "'"); if (rows.Length == 0) return SqlDecimal.Null; if (rows[0]["CalculatedOnTax"] != DBNull.Value) { if ((bool)rows[0]["Cumulative"]) { DataRow[] rows1 = taxTable.Select("[ID] = '" + rows[0]["CalculatedOnTax"].ToString() + "'"); if (rows1.Length == 0) return SqlDecimal.Null; return ((amount + (amount * (decimal)rows1[0]["Rate"]) / new SqlDecimal(100))) * (decimal)rows[0]["Rate"] / new SqlDecimal(100); } else return amount * (decimal)rows[0]["Rate"] / new SqlDecimal(100); } else return amount * (decimal)rows[0]["Rate"] / new SqlDecimal(100); } I want to publish this function making sure the return type has a precision of 2 and a scale of 18. I found that I have to use the SqlFacetAttributes but I am unsure how to do it for a function. I found examples only for a Strored Procedure parameter. Any help appreciated. Txs
-
DataSource binding problemYour Model View Presenter interested me, I have no intention on implementing this for my current project but I will definitely look into this for the future. I didn't find a lot of literature on the subject, it would be of everybody's interest if you had reading suggestion (specifically a good book) on the subject of MVP model. Thanks a lot for your input
-
DataSource binding problemReplying to myself but any better suggestions are welcomed I used the .Leave event on the TextBoxes to force a BindinSource.EdnEdit(); But now I have to manipulate every control individually. Is there a better wayto do this ? Thanks in advance for any input :-D
-
mdi parent problemSomething like DialogResult result = LoginForm.Dialog If (result == DialogResult.Cancel) this.Close();(or Application.Exit();) else ....
-
DataSource binding problemHi, I have a problem binding a DataSource object to multiple TextBoxes on the same form. It seems that the TextBox object is not dynamic, it doesn't change its Text value if the datasource changes. So I did a small experiment to prove this. In a form I initialize three controls and a Members object(derived from a DataSet): Note also that mem[0] returns a DataTable. Members mem = new Members(); mem.ReadRange(1004, 1004); binding = new BindingSource(mem[0], null); textBox1.DataBindings.Add("Text", binding, "FirstName"); textBox2.DataBindings.Add("Text", binding, "FirstName"); dataGridView1.DataSource = mem[0]; Here if I type data in the TextBox1, the datagrid reacts and shows me the modified data on Leave, but TextBox2 doesn't react. Same reaction for TextBox2. If I modify data in the DataGrid's column, none of the Textboxes react until BindingSource.Position changes. So I need a way to make the two text boxes to look at the state of the BindingSource adn detect any changes and react to it I tried also to detect events on BindingSource and BindingSource.CurrencyManager and nothig fires when leaving one of the TextBoxes. Really :confused:
-
Getting registered for SQL NotificationsI build an application that relies on SQL Notification to update a member in clients memory. I used a second select statement to read the members table after the original one because the original was using a view and multiple functions. Works great. But I was wondering for performance issues, is there a way to register for notification without returning a result set? Right now I have the original statement : SELECT [ID],[TemporaryID]...,ISNULL([dbo].GetProvinceName([ProvinceID], [CountryISO3], @Language), [Province]) AS Province...,[dbo].GetUserFullName([LastUpdateUser]) AS LastUpdateUser... FROM [dbo].[vw_MembersFinder] WHERE [LastUpdateDateTime] > @SyncDateTime AND [Status] = @Status So I read right after using : SELECT [ID],[FirstName],[LastName],[Address1],[Address2],[City],[ProvinceID],[PostalCode],[CountryISO3],[ManInvalidAddress] FROM [dbo].[Members] WHERE [Status] = 'A' This way I register correctly for notifications but of course I have to wait for two results sets. Any good ideas?:)
-
Default value selected in Combo Box after another form closes.Not sure why exactely but this is not the only strange behavior I see. I now that forms run on the STA threading model so a form that doesn't have the control is actually not "running". I think that when a form regains the control, it reinitilizes partly its controls, so behaviors like this are to be expected. I learned with time to be very carefull about this. There must be reading to do on this but I never took the time to do it. try to at least understand the difference between STA and MTA, it will answer many of your questions on forms. Good luck ;)
-
DataGridViewComboBoxColumn Values:doh: Don't answer to such a dum question! I wasn't paying attention and data types were not matching ;P Sorry for wasting time
-
Default value selected in Combo Box after another form closes.I am not sure but I think you will have to reset the SelectedIndex agin when the form becomes active. I think it has to do with how forms work ie STA threading model.
-
DataGridViewComboBoxColumn ValuesIn a DataGridViewComboColumn I can set a datasource for multiple choices for entring data and the drop down choices show me the display values to select from. The problem is the DataGridView cells, once not in edit mode, show me the actual database data instead of the DisplayMember's value. Is there a simple way to make the column show display values intead of the actual data ? :confused:
-
Transforming and verifying datesI had to answer to this one myself, this is too funny. My stored procedure was calling another function I wrote that had a similar name :omg: It was a pleasure wasting everybody's time ! :rolleyes:;P
-
Transforming and verifying datesI am probabely be called an idiot rom now on but I can't figure this out, tried everything. Here I have to trasfer in SQL a very disfunctionnal FMP database. This is the function that verifies the dates. The problem I have is this: It works perfectly when the original date (formatted 01/01/1800) is correct but the last part should overwrite any malformed date (anyways that was the intention....) but none get overwritten. I always get the malformed date back. It is as if @DateTest never gets put to False. Help!!:confused: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER FUNCTION [dbo].[GetBirthDate] ( @BirthDate nvarchar(10) ) RETURNS nvarchar(10) AS BEGIN DECLARE @ReturnValue nvarchar(10) DECLARE @DateTest bit SET @DateTest = 'True' IF (@BirthDate = '00/00/00' OR @BirthDate = '' OR @BirthDate = '?' OR @BirthDate IS NULL) SET @ReturnValue = '1800-01-01' ELSE BEGIN IF LEN(@BirthDate) = 10 SET @ReturnValue = SUBSTRING(@BirthDate, 7, 4) + '-' + SUBSTRING(@BirthDate, 4, 2) + '-' + LEFT(@BirthDate, 2) ELSE SET @ReturnValue = '19' + SUBSTRING(@BirthDate, 7, 2) + '-' + SUBSTRING(@BirthDate, 4, 2) + '-' + LEFT(@BirthDate, 2) END IF (SUBSTRING(@ReturnValue, 1, 2) <> '19' AND SUBSTRING(@ReturnValue, 1, 2) <> '20') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 3, 1) < '0' OR SUBSTRING(@ReturnValue, 3, 2) > '9') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 4, 1) < '0' OR SUBSTRING(@ReturnValue, 4, 2) > '9') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 6, 1) < '0' OR SUBSTRING(@ReturnValue, 6, 2) > '1') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 7, 1) < '0' OR SUBSTRING(@ReturnValue, 7, 2) > '9') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 9, 1) < '0' OR SUBSTRING(@ReturnValue, 9, 2) > '3') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 10, 1) < '0' OR SUBSTRING(@ReturnValue, 10, 2) > '9') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 5, 1) <> '-') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 8, 1) <> '-') SET @DateTest = 'False' IF @DateTest = 'False' SET @ReturnValue = '1800-01-01' RETURN @ReturnValue END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO
-
DataGridView prevent editIf this helps anybody I captured the DataGridView.CellParsing event and forced a EndEdit() Not very elegant but it prvents user from entering anything
-
DataGridView prevent editIs there a way to prevent edit of some columns in a DataGridView bound to a DataTable? What I need is prevent edit, the user shouldn't have the opportunity to enter in edit mode if the celll belongs to one of the columns I consider "Read Only".
-
Derived class constructorsMakes sense, thanks for the input
-
How to take mysql backup through .NetCreate a stored precedure that does the backup and execute it from the code
-
Derived class constructorsI don't have a problem understanding inheritence What I am not sure is why since the return type of the GetChanges is DataTable, I expect the DataTable contructor to be called but if I call that same function form a Class derived form DataTable all of a sudden the constructor of the dirived class is called although the return type is still a DataTable, I didn't touch that function. Here is the situation as clear as I can make it: class myType : DataTable { myType():base() {} public someFunction() { code.... DataTable someDataTable = this.GetChanges(); } In the last line a myType seems to be created by the Activator, I would have expected it to create a DataTable, nothing more.
-
Derived class constructorsThe GetChanges function has DataTable as a return type, so yes, at some point the constructor for the DataTable type will be called.