To fix it replace
@Html.TextBoxFor(model => model.CustomerID, new object { @class = "WidthLong" })
With
@Html.TextBoxFor(model => model.CustomerID, new { @class = "WidthLong" })
Watch this on YouTube:
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'checked'
Cannot have multiple items selected in a DropDownList.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Public Enum SomeEnum
Bob = 1
Frank = 2
Gary = 3
Taras = 4
Oleh = 5
End Enum
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim num As Integer =[Enum].GetNames(GetType(SomeEnum)).Length
MessageBox.Show(num)
End Sub
C# - Non-invocable member 'System.Configuration.ConfigurationManager.ConnectionStrings' cannot be used like a method.
Watch this example on YouTube
To fix it replace
System.Configuration.ConfigurationManager.ConnectionStrings("DefaultConnection").ToString(); With
System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
To Fix it go to
Tools
Options
Text Editor
All Languages
General
make sure both Auto list numbers
and Parameter information are checked (not half checked)
Watch this example on YouTube
Fix Error 'Compute' is not a member of 'System.Data.DataRow'.
To fix it replace
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ds As DataSet = LoadData()
Dim query = From rec In ds.Tables(0).AsEnumerable() Select rec
If ds.Tables(0).Rows.Count > 0 Then
For Each r As DataRow In query Dim s As Integer = IIf(r.Compute("Sum(Age)", "Valid = '1'") Is DBNull.Value, 0, r.Compute("Sum(Age)", "Valid = '1'"))
MessageBox.Show(s.ToString)
Next
End If
End Sub
Public Function LoadData() As DataSet
Dim ds As New DataSet
Dim dt As New DataTable
dt.Columns.Add("Valid")
dt.Columns.Add("Age", Type.GetType("System.Int32"))
dt.Rows.Add(New Object() {"1", 33})
dt.Rows.Add(New Object() {"2", 44})
dt.Rows.Add(New Object() {"1", 22})
dt.Rows.Add(New Object() {"1", 22})
ds.Tables.Add(dt)
Return ds
End Function
With
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ds As DataSet = LoadData()
Dim query = From rec In ds.Tables(0).AsEnumerable() Select rec
If ds.Tables(0).Rows.Count > 0 Then
For Each r As DataRow In query Dim s As Integer = IIf(r.Table.Compute("Sum(Age)", "Valid = '1'") Is DBNull.Value, 0, r.Table.Compute("Sum(Age)", "Valid = '1'"))
MessageBox.Show(s.ToString)
Next
End If
End Sub
Public Function LoadData() As DataSet
Dim ds As New DataSet
Dim dt As New DataTable
dt.Columns.Add("Valid")
dt.Columns.Add("Age", Type.GetType("System.Int32"))
dt.Rows.Add(New Object() {"1", 33})
dt.Rows.Add(New Object() {"2", 44})
dt.Rows.Add(New Object() {"1", 22})
dt.Rows.Add(New Object() {"1", 22})
ds.Tables.Add(dt)
Return ds
End Function
Watch this example on YouTube
Error - Additional information: Invalid usage of aggregate function Sum() and Type: String.
To fix replace:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ds As DataSet = LoadData()
Dim query = From rec In ds.Tables(0).AsEnumerable() Select rec
If ds.Tables(0).Rows.Count > 0 Then
For Each r As DataRow In query
Dim s As Integer = IIf(r.Table.Compute("Sum(Age)", "Valid = '1'") Is DBNull.Value, 0, r.Table.Compute("Sum(Age)", "Valid = '1'"))
MessageBox.Show(s.ToString)
Next
End If
End Sub
Public Function LoadData() As DataSet
Dim ds As New DataSet
Dim dt As New DataTable
dt.Columns.Add("Valid") dt.Columns.Add("Age")
dt.Rows.Add(New Object() {"1", 33})
dt.Rows.Add(New Object() {"2", 44})
dt.Rows.Add(New Object() {"1", 22})
dt.Rows.Add(New Object() {"1", 22})
ds.Tables.Add(dt)
Return ds
End Function
With
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ds As DataSet = LoadData()
Dim query = From rec In ds.Tables(0).AsEnumerable() Select rec
If ds.Tables(0).Rows.Count > 0 Then
For Each r As DataRow In query
Dim s As Integer = IIf(r.Table.Compute("Sum(Age)", "Valid = '1'") Is DBNull.Value, 0, r.Table.Compute("Sum(Age)", "Valid = '1'"))
MessageBox.Show(s.ToString)
Next
End If
End Sub
Public Function LoadData() As DataSet
Dim ds As New DataSet
Dim dt As New DataTable
dt.Columns.Add("Valid") dt.Columns.Add("Age", Type.GetType("System.Int32"))
dt.Rows.Add(New Object() {"1", 33})
dt.Rows.Add(New Object() {"2", 44})
dt.Rows.Add(New Object() {"1", 22})
dt.Rows.Add(New Object() {"1", 22})
ds.Tables.Add(dt)
Return ds
End Function
Query to group by time intervals - group by 15 minutes time intervals
Watch this example on YouTube
select count(id) as NumberOfOrders,
DatePart(Year, MyDate) as TransactionYear,
DatePart(MONTH, MyDate) as TransactionMonth,
DatePart(DAY, MyDate) As TransactionDate,
DatePart(Hour, MyDate) As TransactionHour,
DatePart(Minute, MyDate)/15 As TransactionInterval,
Convert(Varchar, DatePart(Hour, MyDate)) + Case DatePart(Minute, MyDate) /15 When 0 Then ':00' When 1 Then ':15'
When 2 Then ':30' When 3 Then ':45' End as TransInterval
From IntervalTest
Group By
DatePart(Year, MyDate) ,
DatePart(MONTH, MyDate),
DatePart(DAY, MyDate),
DatePart(Hour, MyDate) ,
DatePart(Minute, MyDate)/15
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JavaScript Check if date is valid.aspx.cs" Inherits="WebTest.JavaScript_Check_if_date_is_valid" %>
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 200000; i++)
{
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + Environment.NewLine);
} string sHeader = "attachement; filename=test.csv"; var exc = HttpContext.Current.Response; exc.Clear(); exc.ContentType = "application/octet-stream"; exc.ContentEncoding = System.Text.Encoding.Default; exc.AppendHeader("Content-Disposition", sHeader); exc.Write(sb.ToString()); exc.Flush(); exc.Clear(); exc.Close();
With
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 200000; i++)
{
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + ",");
sb.Append("some data here " + Environment.NewLine);
}
public ActionResult TestPage(TESTEntities model = null)
{
var test = (from z in model.Customers2
select z);
if (!String.IsNullOrEmpty(model.Customers2.First().CustomerFirstName))
{ test = model.Customers2.Where(s => s.CustomerFirstName != null) && (s => s.FirstOrDefault().ToString().Trim().Equals(model.Customers2.FirstOrDefault().CustomerFirstName.Trim()));
}
return View();
}
With
public ActionResult TestPage(TESTEntities model = null)
{
var test = (from z in model.Customers2
select z);
if (!String.IsNullOrEmpty(model.Customers2.First().CustomerFirstName))
{
//test = model.Customers2.Where(s => s.CustomerFirstName != null) &&
// (s => s.FirstOrDefault().ToString().Trim().Equals(model.Customers2.FirstOrDefault().CustomerFirstName.Trim())); test = model.Customers2.Where(s => s.CustomerFirstName == null ? false : s.CustomerFirstName.Equals("AAA"));
}
return View();
}
Watch this example on YouTube: to fix it replace
public ActionResult ImportFile(HttpPostedFileBase file)
{
if (Request.Files.Count > 0)
{
var fil = Request.Files[0];
if (fil != null && fil.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Images/"), fileName);
file.SaveAs(path);
}
}
return View(); with
public ActionResult ImportFile(HttpPostedFileBase file)
{
if (Request.Files.Count > 0)
{
var fil = Request.Files[0];
if (fil != null && fil.ContentLength > 0)
{
var fileName = System.IO.Path.GetFileName(file.FileName);
var path = System.IO.Path.Combine(Server.MapPath("~/Images/"), fileName);
file.SaveAs(path);
}
}
return View();
Watch this example on YouTube: Error while executing the following code:
public IEnumerable<SelectListItem> Months
{
get
{
return DateTimeFormatInfo
.InvariantInfo
.MonthNames
.Select((monthName, index) => new SelectListItem
{
Value = (index + 1).ToString(),
Text = monthName
});
}
}
To fix it add the following using:
using System.Globalization;
Watch this on YouTube: error while executing the following code:
public IEnumerable<SelectListItem> Months
{
get
{
return DateTimeFormatInfo
.InvariantInfo
.MonthNames
.Select((monthName, index) => new SelectListItem
{
Value = (index + 1).ToString(),
Text = monthName
});
}
} To fix it - add the following using: using System.Globalization;
SortAndPage class
namespace MvcSortAndFilterAndPage.Models { public class SortAndPage { public string SortField { get; set; } public string SortDirection { get; set; } public int PageSize { get; set; } public int PageCount { get; set; } public int CurrentPageIndex { get; set; } } } Customer Custom class
namespace MvcSortAndFilterAndPage.Models { public class CustomerCustom :SortAndPage { public IEnumerable<Customers2> cust { get; set; } public IEnumerable<Customers2> custDDL { get; set; } public string SelectedFirstName { get; set; } public string SelectedLastName { get; set; } } }
add the following to _layout.cshtml
@Scripts.Render("~/Scripts/jquery-1.8.2.min.js") @Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.js") </head>
Here is modified part of CustomerController
using MvcSortAndFilterAndPage.Models;
namespace MvcSortAndFilterAndPage.Controllers { public class CustomerController : Controller { private TESTEntities db = new TESTEntities();
// // GET: /Customer/
public ActionResult Index(CustomerCustom model = null) { int i; if (model != null) { i = model.CurrentPageIndex; } model = new CustomerCustom { cust = db.Customers2.ToList(), custDDL = db.Customers2.ToList() }; var res = (from s in model.cust select s); res = res.ToList(); if (model.CurrentPageIndex == 0) { model.CurrentPageIndex = 0; } model.PageSize = 2; model.PageCount = ((res.Count() + model.PageSize - 1) / model.PageSize); if (model.CurrentPageIndex > model.PageCount) { model.CurrentPageIndex = model.PageCount; } model.cust = res.Skip(model.CurrentPageIndex * model.PageSize).Take(model.PageSize);
public class test
{
public string Name { get; set; }
public int Age { get; set; }
}
public partial class LINQ_List_Group_Count_test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<test> myList = new List<test>(){
new test(){Name ="Frank", Age =80},
new test(){Name = "Bob", Age = 30},
new test(){Name = "Bob", Age = 50},
new test(){Name = "John", Age = 40}
};
var AllNames = from m in myList select m.Name;
var UniqueNames = from a in myList
group a by a.Name into g
select g.Count();
Response.Write(UniqueNames.Count().ToString());
Response.Write("<br />");
Response.Write(AllNames.Count().ToString());