|
If your print quality is down then please check your printer 'printing density' or 'Color Density'
Hopefully its helps you.
|
|
|
|
|
So I have a MVC website project using Entity Framework.
I'm new to c#, so perhaps this is a c# issue. And I'm new to MVC as well.
I wrote a seperate project for the EF, and attached it to the MVC Project so I can work on both at the same time.
Everything was fine until I changed the namespaces in the EF DLL.
I renamed the namespace for all the Model classes DAL_MODELS
and the Context to just DAL
I removed the reference, and added it back again.
Whats weird, is I can add the DAL in the Controller files, but not the files I wrote in App_Code.
I did use folders to organize the files
\App_Code\EntityFramework\Admin
\App_Code\EntityFramework\Contact Us
Reference my DLL Assembly
The DLL is names MVC.DataAccessLayer with the 2 namespaces below.
Using DAL;
Using DAL_MODELS;
I wanted to rename the namespaces to the files in App_Code, but not having a luck with it.
Like to App_Code.EntityFramework so I can make 1 reference to it.
I just scratching my head on this.
|
|
|
|
|
I had to mark the files as compile
And added a reference to the DLL to Web.Config
|
|
|
|
|
I have a datatable where data represented like this
ID Code Effective Date
111 103 01/01/2015
111 104 01/01/2014
111 105 01/01/2013
111 103 01/01/2014
111 103 01/01/2013
111 103 01/01/2012
112 103 01/01/2012
112 103 01/01/2013
I need to create a new table with the latest 3 effective date per each ID and Code:
Result:
ID Code Effective Date1 Effective Date2 Effective Date3
111 103 01/01/2015 01/01/2014 01/01/2013
111 104 01/01/2014
111 105 01/01/2013
112 103 01/01/2013 01/01/2012
How do I do this?
I have started with cloning the table structure(myDataTable already have Columns: Effective Date1 Effective Date2 Effective Date3)
Dim copyDataTable As DataTable
copyDataTable = myDataTable.Clone()
modified 28-Oct-15 15:55pm.
|
|
|
|
|
A spot of LINQ makes this relatively easy:
Dim data = myDataTable.AsEnumerable().GroupBy(Function (r) New With
{
Key .ID = r.Field(Of Integer)("ID"),
Key .Code = r.Field(Of Integer)("Code")
},
Function (key, rows) New With
{
Key .ID = key.ID,
Key .Code = key.Code,
.Dates = rows.Select(Function (r) r.Field(Of DateTime?)("Effective Date")) _
.OrderByDescending(Function (d) d).Take(3).ToList()
})
Dim result As New DataTable()
result.Columns.Add("ID", GetType(Integer))
result.Columns.Add("Code", GetType(Integer))
result.Columns.Add("Effective Date 1", GetType(DateTime))
result.Columns.Add("Effective Date 2", GetType(DateTime))
result.Columns.Add("Effective Date 3", GetType(DateTime))
For Each item in data
result.Rows.Add(item.ID, item.Code,
item.Dates.ElementAtOrDefault(0),
item.Dates.ElementAtOrDefault(1),
item.Dates.ElementAtOrDefault(2))
Next
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have added Imports System.Linq to my declaration however
Getting errors below:
'AsEnumerable' is not a member of 'System.Data.DataTable'.
item' is not declared. It may be inaccessible due to its protection level
|
|
|
|
|
Make sure you have a reference to the System.Data.DataSetExtensions assembly, and an Imports System.Data declaration at the top of your file.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have added all references however still the following lines won't compile.
Option Strict On requires all variable declarations to have an 'As' clause.
Dim data = myDataTable.AsEnumerable().GroupBy(Function(r) New With {Key .ID = r.Field(Of Integer)("ID"), Key .Code = r.Field(Of Integer)("Code")},
and
'item' is not declared. It may be inaccessible due to its protection level.
For Each item In data
|
|
|
|
|
You're using an anonymous type, so you can't give the variables an explicit type.
Try setting Option Infer On , which should allow the compiler to infer the type for you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
it worked. Now I am facing different issue when adding a new row into new table with non key columns
result.Rows.Add .... item.EENAML.. etc.
Could you tell me what am I doing wrong?
Here my full code
Dim data = myDataTable.AsEnumerable().GroupBy(Function(r) New With {Key .EEGRP = r.Field(Of String)("EEGRP"), Key .EESSN = r.Field(Of String)("EID")},
Function(key, rows) New With
{
Key .EEGRP = key.EEGRP,
Key .ESSN = key.EID,
.Dates = rows.Select(Function(r) r.Field(Of DateTime?)("DEIBCY") & ("DIIBYR") & ("D.DIIBMT") & ("DEIBDY")) _
.OrderByDescending(Function(d) d).Take(3).ToList()
})
Dim result As New DataTable
result = myDataTable.Clone()
For Each item In data
result.Rows.Add(item.EEGRP,item.EID, item.EENAML,item.EENAMF,item.EENAMM,item.EEADD1,item.EEADD2,,,, _
|
|
|
|
|
What's the error message?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
'FIELD' is not a member of '<anonymous type="">'; it does not exist in the current context.
|
|
|
|
|
Make sure you have a reference to the System.Data.DataSetExtensions assembly, and an Imports System.Data declaration at the top of your file.
The Field(Of T) method is an extension method defined in that namespace and assembly:
DataRowExtensions.Field<T> Method (DataRow, String)[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
When I add
Imports System.Data.DataSetExtensions
Module ModuleMain...
it saying it can't be found.
I do have reference added to the project.
|
|
|
|
|
The assembly is System.Data.DataSetExtensions ; the namespace is System.Data .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
When I change my project properties to .net 3.5 I was able to add
Imports System.Data.DataSetExtensions
however even with that I still having issues with no key fields for selecting
is not a member of '<anonymous type="">'; it does not exist in the current context
For Each item In data
result.Rows.Add(item.EEGRP,item.ESSN, item.EENAML,item.EENAMF,item.EENAMM,item.EEADD1,item.EEADD2,...._
|
|
|
|
|
please can tell anyone about asp.net architecture in simple way
|
|
|
|
|
|
Hello,
I want to create the unit test for the windows 10 universal app but I don't want to use the Microsoft Unit test app.
Could anyone recommend me the third party tool to test the unit test cases fro the windows 10 universal app.
Thanks in advance.
|
|
|
|
|
Hello
The above is the error message I am getting followed by a long Stack Trace.
I have a small form here http://www.dimadayoub.net/contact.aspx[^] and, to test it, I leave the email field blank on purpose (when I do the same for the other two fields, Name and Message, I get an on screen warning to complete the fields - which is what should happen).
When I do the same with the email field, I get the above server error. The relevant code I have is this:
<p><asp:Label ID="Email" runat="server" Text="Email"></asp:Label>
<asp:TextBox ID="your_email" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="*" ControlToValidate="your_email"
ValidationGroup="vgSubmit" ForeColor="#FF6666"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" Display="Dynamic" ErrorMessage="Please complete the Email field"
ValidationGroup="vgSubmit" ControlToValidate="your_email"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></p>
What should I be correcting, please?
|
|
|
|
|
Remove the ValidationGroup="vgSubmit" attribute from both validators. Neither of your other validators have a validation group set, and neither does your submit button.
Specifying Validation Groups | MSDN[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Many thanks, Richard, for your reply.
I have done as you suggested and made a couple of other alterations.
The code now looks like this:
<p><asp:Label ID="Email" runat="server" Text="Email"></asp:Label>
<asp:TextBox ID="your_email" runat="server" ></asp:TextBox>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="SingleParagraph" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="*" ControlToValidate="your_email" Display="None"
ForeColor="#FF6666"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" Display="None" ErrorMessage="Please complete the Email field"
ControlToValidate="your_email"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></p>
The result is that when I complete the 3 fields correctly, the form is sent.
When I complete the Name and Message fields, and Email field (without the @), I get an on screen error: 'Please complete the Email field' (for some reason it is in a white font and not the red of ="#FF6666"). I will amend that so it reads 'Please enter a valid email address'.
When I leave the email field blank entirely (the form does not get sent, which is fine), but I can see a little asterisk. I presume that asterisk is this:
ErrorMessage="*"
Can I not replace that asterisk with the on screen message: 'Please complete the Email field'?
Thanks again.
|
|
|
|
|
The ErrorMessage is the message that gets displayed in the ValidationSummary . The Text is the message that gets displayed in-line. If you set the ErrorMessage without setting the Text , the same message is used in both places.
You've used Display="None" , so the validators aren't showing up in-line. Instead, the ValidationSummary is showing all of the error messages next to the email field. You haven't applied any styles to the ValidationSummary , which is why the messages are white.
I'd be inclined to put a single ValidationSummary at the top of your form. Then, for each validator, set the ErrorMessage to the message you want to display, the Text to * , and the Display to Dynamic .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks again.
I think I am beginning to see what you mean - it will take some time for me to digest all your kind points. Yes, I can make those changes and see the results.
Do you mean apply CSS to ValidationSummary1, and not RegularExpressionValidator2, in order to add style to 'Please complete the Email field'?
|
|
|
|
|
You need to add style to both - the style on the ValidationSummary will apply to the summary messages at the top of the form, and the style on the individual validators will apply to the "*" that appears next to an invalid field.
I generally use a theme[^] folder with a .skin file to apply the same CssClass to all validators, and a CssClass to the ValidationSummary . That way, the settings are consistent across the site, and the style settings remain in the CSS file where they belong.
If you don't want to add a theme to your site, you'll need to set the CssClass on each validator and ValidationSummary wherever you use them.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|