"Cannot change DataType of a column once it has data" error in Visual Studio 2005 DataSet Designer - visual-studio

I've got a DataSet in VisualStudio 2005. I need to change the datatype of a column in one of the datatables from System.Int32 to System.Decimal. When I try to change the datatype in the DataSet Designer I receive the following error:
Property value is not valid. Cannot change DataType of a column once
it has data.
From my understanding, this should be changing the datatype in the schema for the DataSet. I don't see how there can be any data to cause this error.
Does any one have any ideas?

I get the same error but only for columns with its DefaultValue set to any value (except the default <DBNull>). So the way I got around this issue was:
Column DefaultValue : Type in <DBNull>
Save and reopen the dataset

Since filled Datatables do not entertain a change in the schema a workaround can be applied as follows:
Make a new datatable
Use datatable's Clone method to
create the datatable with the same
structure and make changes to that
column
In the end use datatable's ImportRow
method to populate it with data.
HTH

For those finding this via Google and you have a slightly different case where your table has got data and you add a new column (like me), if you create the column and set the datatype in separate statements you also get this same exception. However, if you do it in the same statement, it works fine.
So, instead of this:
var column = myTable.Columns.Add("Column1");
column.DataType = typeof(int); //nope, exception!
Do this:
var column = myTable.Columns.Add("Column1", typeof(int));

I have found a work around. If I delete the data column and add it back with the different data type, then it will work.

Close the DataSet in the visual designer
Right click the dataset, choose Open With...
Choose XML (Text) Editor
Find the column in the XML, in your dataset it will look something like:
<xs:element name="DataColumn1"
msprop:Generator_ColumnVarNameInTable="columnDataColumn1"
msprop:Generator_ColumnPropNameInRow="DataColumn1"
msprop:Generator_ColumnPropNameInTable="DataColumn1Column"
msprop:Generator_UserColumnName="DataColumn1"
type="xs:int"
minOccurs="0" />
Change the type="xs:int" to type="xs:decimal"
Save and close the XML editor
You may need to right click the DataSet again and choose Run Custom Tool

Its an old Question but it still can happen at VS 2019
Solution:
Change the DefaultValue to <DBNull>
Save the Dataset
Close the DataSet Designer
Re-Open the Designer
Now it should be possible to change the type without any problem.

Related

how to change columns position in vb6?

I am working with a spread designer in visual basic 6 and am looking to change the display index of my table. I am adding extra columns and I need to rearrange them to match another form.
I am using visual basic 6 with spread designer 6.0
I have tried the below when loading the form:
lstTheLines.Col(1).DisplayIndex = 1
lstTheLines.Columns(25).DisplayIndex = 2
does anyone know how to do this without having to delete and re-add all columns?
The best way I found so far was to add the columns in the place I want using the spread designer and create an Enum in the code for each column index. This way I can give the columns a name and use that instead when populating the data. The benefit to this is that I can now rename the columns or add new ones and I just need to change the names around in the Enum given that the column type is correct.

Crystal Report not filtering SQL records based on selection formula

unfortunately I'm not an expert of Crystal Report, so I'll post here my question hoping for any help about my issue.
I want to display inside my report the result of a filter on a SQL RecordSet; this RecordSet is looked up from an a single table, of which I want to show some fields of my SQL table, while the filter I want to apply is based on a field parameter (defined static) that I'm trying to set programmatically.
Here below I attached my code where I'm applying the record selection formula, I tried also hard-coding the value instead of passing it through a dropdown selection:
ReportDocument RPT_Doc = new ReportDocument();
RPT_Doc.Load(RPT_Path_Name, OpenReportMethod.OpenReportByDefault);
ApplyConnInfos(ref RPT_Doc);
RPT_Doc.SetParameterValue("data_riferimento", "20161001");
RPT_Doc.RecordSelectionFormula = "{viaggi.data_part_pre} = '20161001'";
crystalReportViewer1.ReportSource = RPT_Doc;
In the first image attached you can find the field parameter definition, while second image is the record selection formula I defined inside my report:
The report always shows all the records of my table (more than ten thousand rows), instead of displaying a filtered RecordSet. The odd thing is Preview function from Visual Studio works like a charm; it prompts the field value, once I confirm the value the viewer displays the report with the rows filtered as I expect..
What am I missing from report/C# program configuration to make the record selection work?
Thank you in advance for any suggestion you can give me :)
Leonardo
Ok, finally we got the solution to our issue.
We found the CrystalReportViewer object used to display generated reports has 2 different properties, SelectionFormula and ViewTimeSelectionFormula; both has default value set to empty string.
Below I attached the picture of .Designer.cs file with the 2 properties valued:
We commented those 2 properties and the selection formulas and field parameters applied through code / report designer worked again.

SISS - Automatically Create Column ( Derived Colomn)

I would like to now, if has a way to create automatically columns on Data Conversion (SISS) .
I have an Excel Source with a med19g (which represents 2019 year).
Next step, I have my Data Conversion:
As you see, med19g columns is on it.
So, next year will be added a med20g (represents 2020 year) column in Excel, and I'd like to find a way to add this column automatically or way to prevent that column on my solution (Data Conversion).
Does someone have any idea how I can I get it?
I'm using Visual Studio 2015
Thanks in advance
You will need to use "Flat file source" in the data flow to get the source file. After that, Use "Derived Column" under Data Flow Transformations category and add the desired field like below:
You can edit your output column name later by using Advanced Editor (Right click on Derived column)
If you need to check whether your source file has the same column or not already, you can add a "Script Component" (Source) between the "Get Flat File" and "Derived Column" components. In the script, check your column names and use a boolean value to decide if a column name is existing already or not. How you can do is explained clearly in this link:
https://dichotic.wordpress.com/2006/11/01/ssis-test-for-data-files-existence/

ssrs questions regarding drop down menu and dataset

I am using SSRS through VS 2010 and have the following questions:
Can I define a drop down menu without defining a dataset?
I have a dataset defined, is there anyway to add "manual" values to this dataset? The background requirement of this is that the report query is based on this dataset. However I want to have an option in the dataset where it says "all" in order to allow the user to see everything instead of narrowing down results based on the dataset.
Thanks,
Bruce
I am a newbie to SQL Server reports and found my answers:
For the first one, can simply create a table and use a dataset on the created table with customzied values.
Same goes for the second one, the manual data can be added to the table itself.

Entity Framework is padding out my text fields although they are not Fixed Length

I am building an MVC3 site using Entity Framework 4 and I'm having a problem with fixed length fields.
When I look at my code during debug it shows that MyEntity.Title="Hello name " with the title padded out to the maximum length of the field.
This is usually a question of having fixed field length in the EDMX file or using a char data type on the underlying database rather than a varchar. In this case neither of those is correct, however it is possible that the problem fields were of fixed length originally. I have manually changed each field in the EDMX ( and the model has been regenerated ) and the fields were never fixed length in the database ( which was the starting point for the application ) so I guess that the need to pad out the fields is being stored somewhere in the Entity Framework configuration and hasn't been updated.
The problem occurs in new records when they are added to the database- when the object is created the Title will be correct, when it is instanciated from the database it is padded.
What do I need to do in order to get rid of the padding, which is really screwing up my string comparisons unless I trim everything?
It turns out that in the .EDMX file the padded files were still listed as nchar. This wasn't visible through the Model Editor, the only way to change it was to right-click on the model in Visual Studio and select "open with..." then use an XML editor. The offending fields looked like this:
<Property Name="MyProperty" Type="nchar" Nullable="false" MaxLength="50" />
Changing the Type to nvarchar and running the template again seemed to clear the problem up.
Existing fields do not get updated in the model when you update it from the database. You either have to delete the entities from the model, or manually change those fields to the new values.
Check the property types in the Model Browser and make sure they are correct.
Change your Title field to have the Fixed Length property set equal to true. It's probably defaulting to none :)
Make sure you make the change in the dbase first and then update your edmx.

Resources