I had a report that functioned well but crashed recently. The error messages were not helpful.
The main page displayed a dashboard with multiple panels that held data tables, but the dashboard was broken suddenly.
I discovered that when I deleted the dashboard and all panels, and I replaced them with an empty dashboard and an empty panel, the report was still broken and shown me the same error message which is showing below.
Has anyone dealt with the error before? Are there any solutions? Any that are simple and small?
Source code and Error messages
source code image
Logi Debugger Trace Report
There was an error while processing your request.
The error was:
**There was a problem evaluating an expression. The error was: "Error: in expression ".**
Compute Data Operation Plan
View Data Operation PlanData Operation Group 1:
- Retrieve data
Data Operation Group 2:
- ReportCenterFilter ID="rdReportCenterFilter"
Data Operation Group 3:
- CompareFilter ID="cmpIsVisual"
- CompareFilter ID="cmpNotCurrentUser"
Data Operation Group 4:
- DeDuplicateFilter
Data Operation Group 5:
- AggregateColumn ID="RowCount"
Data Operation Group 6:
- DataLayerLink ID="dlSharedFrom"
Data Operation Group 1 of 6
View Group Details (1 Items)Details for Data Operation Group 1 of 6
Load data into engine
- Running as a separate Data Operation Group since the next step requires access to the full data file.
Generating this debugger information increases the overall elapsed time.
logi debugger img 1
logi debugger img 2
Detailed Error Report
There was an error while processing your request.
Message:
There was a problem evaluating an expression. The error was: "Error: in expression ".
Source:
rdServer
Stack Trace:
at rdServer.rdScriptEvaluator.Eval(String sExpression, String sErrorResult, Int32 iValueCountPassed)
at rdServer.PageBuilder.k(XmlElement A_0)
at rdServer.PageBuilder.ax(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.ax(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.q(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.s(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.r(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.q(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.s(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.r(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.q(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.s(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.r(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.ax(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.q(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.s(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.r(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ah(XmlElement& A_0, String A_1)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.ax(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.rdDashboard.a(XmlElement& A_0, XmlElement A_1)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.az(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.ak(XmlElement A_0)
at rdServer.PageBuilder.a6(XmlElement& A_0)
at rdServer.PageBuilder.bf(XmlElement& A_0)
at rdServer.PageBuilder.BuildHtml(String RequestedPage)
at rdServer.ResponseBuilder.BuildResponse()
Inner error:
Message:
Error: in expression
Source:
Microsoft.VisualBasic
Stack Trace:
Error: in expression
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.InvokeMethod(Method TargetProcedure, Object[] Arguments, Boolean[] CopyBack, BindingFlags Flags)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at rdServer.rdScriptEvaluator.Eval(String sExpression, String sErrorResult, Int32 iValueCountPassed)
rdServer error image 1
rdServer error image 2
I have no errors when copying your code into a new report, so I suspect there might be an issue with your project directory (a support file, perhaps?). I would suggest starting a new project, and slowly copying over your reports one at a time, to confirm; alternatively, restore the directory from a backup, if possible, to see if that resolves the error.
<?xml version="1.0" encoding="UTF-8"?>
<Report ID="Dashboard">
<StyleSheet StyleSheet="newStyleSheet.css" />
<ReportHeader />
<Body>
<Dashboard2 ID="testDash" SaveFile="#Function.AppPhysicalPath~\SavedDashboards\a.Dashboard_Default_.xml">
<Panel Caption="panel header" ID="pnlTest1">
<PanelContent>
<Label Caption="test Label" />
</PanelContent>
</Panel>
</Dashboard2>
</Body>
<DefaultRequestParams Interval="0" />
<ReportFooter />
<ideTestParams />
</Report>
Related
So, my array is not looping through the next element instead its just returning this. Am Missing a loop somewhere?
Here is what mArray Return now:
mArray {Length=21} String(,)
(0,0) "Saturday" String
(0,1) "12:00" String
(0,2) "5:00" String
(1,0) "Saturday" String
(1,1) "12:00" String
(1,2) "5:00" String
(2,0) "Saturday" String
(2,1) "12:00" String
(2,2) "5:00" String
(3,0) "Saturday" String
(3,1) "12:00" String
(3,2) "5:00" String
(4,0) "Saturday" String
(4,1) "12:00" String
(4,2) "5:00" String
(5,0) "Saturday" String
(5,1) "12:00" String
(5,2) "5:00" String
(6,0) "Saturday" String
(6,1) "12:00" String
(6,2) "5:00" String
This is my desired Results:
mArray {Length=21} String(,)
(0,0) "Sunday" String
(0,1) "12:00" String
(0,2) "5:00" String
(1,0) "Monday" String
(1,1) "10:00" String
(1,2) "8:00" String
(2,0) "Tuesday" String
(2,1) "10:00" String
(2,2) "8:00" String
(3,0) "Wednesday" String
(3,1) "10:00" String
(3,2) "8:00" String
(4,0) "Thursday" String
(4,1) "10:00" String
(4,2) "6:00" String
(5,0) "Friday" String
(5,1) "10:00" String
(5,2) "6:00" String
(6,0) "Saturday" String
(6,1) "12:00" String
(6,2) "5:00" String
XML File For reference
<BranchHours>
<Hours>
<DayOfWeek>Sunday</DayOfWeek>
<Open>12:00</Open>
<Close>5:00</Close>
</Hours>
<Hours>
<DayOfWeek>Monday</DayOfWeek>
<Open>10:00</Open>
<Close>8:00</Close>
</Hours>
<Hours>
<DayOfWeek>Tuesday</DayOfWeek>
<Open>10:00</Open>
<Close>8:00</Close>
</Hours>
<Hours>
<DayOfWeek>Wednesday</DayOfWeek>
<Open>10:00</Open>
<Close>8:00</Close>
</Hours>
<Hours>
<DayOfWeek>Thursday</DayOfWeek>
<Open>10:00</Open>
<Close>6:00</Close>
</Hours>
<Hours>
<DayOfWeek>Friday</DayOfWeek>
<Open>10:00</Open>
<Close>6:00</Close>
</Hours>
<Hours>
<DayOfWeek>Saturday</DayOfWeek>
<Open>12:00</Open>
<Close>5:00</Close>
</Hours>
</BranchHours>
Here is the Function:
Public Shared Function BranchOpenClose(ByVal branchCode As String) As Array
'set XML URL path
Dim URLString As String = "url/branchesTesting.xml"
'load URL Path
Dim xmlDoc As XDocument = XDocument.Load(URLString)
'decalre a 2- dimensional array of string as:
Dim mArray(6, 2) As String
Dim i As Integer
' Dim j As String
'Find XML Path Using Passed BranchCode variable & Select Hours Element Values
Dim Items = From BranchHours In xmlDoc.XPathSelectElements("/BranchesInfo/BranchInfo[BranchId='" & branchCode & "']/BranchHours/Hours") _
Select DayOfWeek = ((BranchHours.Elements("DayOfWeek").ToArray.Value)), _
Open = ((BranchHours.Elements("Open").ToArray.Value)), _
Close = ((BranchHours.Elements("Close").ToArray.Value))
For Each Hours In Items
For i = 0 To 6
mArray(i, 0) = Hours.DayOfWeek
mArray(i, 1) = Hours.Open
mArray(i, 2) = Hours.Close
Next
Next
Return mArray
End Function
...................................................................................
This is the solution I was looking for.
I had a loop inside another loop it goes through each hour, and then goes again from 0 -6.... I just needed a simple counter here instead of the additional FOR.
This is why it rewrote my values over and over again
For Each Hours In Items
mArray(i, 0) = Hours.DayOfWeek
mArray(i, 1) = Hours.Open
mArray(i, 2) = Hours.Close
i+=1
Next
Cheers
You don't need to populate the array yourself, use ToArray():
Public Shared Function BranchOpenClose(ByVal branchCode As String) As Array
'set XML URL path
Dim URLString As String = "url/branchesTesting.xml"
'load URL Path
Dim xmlDoc As XDocument = XDocument.Load(URLString)
Dim i As Integer
'Find XML Path Using Passed BranchCode variable & Select Hours Element Values
Dim Items = From BranchHours In xmlDoc.XPathSelectElements("/BranchesInfo/BranchInfo[BranchId='" & branchCode & "']/BranchHours/Hours") _
Select DayOfWeek = ((BranchHours.Elements("DayOfWeek").ToArray.Value)), _
Open = ((BranchHours.Elements("Open").ToArray.Value)), _
Close = ((BranchHours.Elements("Close").ToArray.Value))
Return Items.ToArray()
End Function
Use anonymous method with xml linq
Imports System.Xml
Imports System.Xml.Linq
Module Module1
Dim FILENAME As String = "c:\temp\test.xml"
Sub Main()
Dim doc As XDocument = XDocument.Load(FILENAME)
Dim results = doc.Descendants("Hours").Select(Function(x) New With { _
.dayOfWeek = x.Element("DayOfWeek").Value, _
.open = CType(x.Element("Open"), DateTime),
.close = CType(x.Element("Close"), DateTime)
}).ToList()
End Sub
End Module
Here is screen image of results
So whenever i Click the SignUp Button,the browser shows me this error:
"Syntax error: Missing operand after '#live' operator."
And Stack Trace:
> [SyntaxErrorException: Syntax error: Missing operand after '#live' operator.]
System.Data.ExpressionParser.Parse() +2082709
System.Data.DataExpression..ctor(DataTable table, String expression, Type type) +131
System.Data.DataTable.Select(String filterExpression) +107
Class1.Authenticate(String id, String pas) +196
Class1.add(String Email, String pas, String Name, DateTime SignDate) +205
SignUp.Button1_Click(Object sender, EventArgs e) +148
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9692746
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3562
This is my Class Code for the website:
Public Class Class1
Private Shared dsPubs As DataSet
Public dr As DataRow
Public Function Authenticate(ByVal id As String, ByVal pas As String) As Integer
Dim strConnectionString As String = "Integrated Security=SSPI;Initial Catalog=Shop;Data Source=."
Dim instsqlconnection As SqlConnection = New SqlConnection(strConnectionString)
instsqlconnection.Open()
Dim daCstmrs As New SqlDataAdapter("Select * From Customer_Detail", instsqlconnection)
dsPubs = New DataSet("Customer")
daCstmrs.Fill(dsPubs, "login")
instsqlconnection.Close()
Dim drResult As DataRow() = dsPubs.Tables("login").Select(" EmailAddress = " + id.ToString())
If (drResult.Length > 0) Then
If drResult(0)("Password").ToString().Trim() = pas Then
Return 1
Else
Return 2
End If
Else
Return 0
End If
End Function
Public Function add(ByVal Email As String, ByVal pas As String, ByVal Name As String, ByVal SignDate As Date) As Integer
Dim strConnectionString As String
Dim instsqlconnection As SqlConnection
strConnectionString = "Integrated Security=SSPI;Initial Catalog=Shop;Data Source=."
instsqlconnection = New SqlConnection(strConnectionString)
instsqlconnection.Open()
Dim daCstmrs As New SqlDataAdapter("Select * From Customer_Detail", instsqlconnection)
Dim dsPubs As New DataSet("Customer")
Dim table As DataTable = New DataTable("login")
daCstmrs.Fill(dsPubs, "login")
instsqlconnection.Close()
Dim a As Integer = Authenticate(Email, pas)
If (a = 0) Then
Dim cmdBuilder As SqlCommandBuilder = New SqlCommandBuilder(daCstmrs)
Dim dr As DataRow
dr = dsPubs.Tables("login").NewRow()
dr("EmailAddress") = Email
dr("Password") = pas
dr("Name") = Name
dr("DateOBirth") = SignDate
dsPubs.Tables("login").Rows.Add(dr)
daCstmrs.Update(dsPubs, "login")
Return 1
Else
Return 2
End If
End Function
And Finally this is the SignUp button OnClick code:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim p As New Class1
Dim y As Integer
y = p.add(Me.EmailSignUp.Text, Me.PassSignUp.Text, Me.NameSignUp.Text, Me.DobSignUp.Text)
If (y = 1) Then
Response.Redirect("CheckOut.aspx")
Else
Me.Label6.Text = "add failed "
End If
End Sub
I don't know what i should do to avoid getting the error on the browser and to successfully add the record to the database.I know that there's something about the '#' that should be fixed but don't know what.
After a lot of trying to narrow where my problem is,i found out that my problem is coming from this line:
Dim drResult As DataRow() = dsPubs.Tables("login").Select(" EmailAddress = " + id.ToString())
Something related to the id.ToString,it only works if i enter a number,otherwise it keeps showing me an error!
As #Andrew Morton said , adding single quotes around id string will fix the problem!
Dim drResult As DataRow() = dsPubs.Tables("login").Select("
EmailAddress = " + id.ToString())
Will become :
Dim drResult As DataRow() =
dsPubs.Tables("login").Select("EmailAddress = '" & id & "'")
I have date in string format 20/05/2016:
string weekEndDate="20/05/2016"
when convert it to DateTime,An error Occured:
DateTime EndDate = Convert.ToDateTime(weekEndDate);
String was not recognized as a valid DateTime.
Try changing your string format to "yyyy-mm-dd" or "yyyy/mm/dd"
You can also use DateTime.TryParse method to parse date from any date format. See examples
You can use ParseExact method to parse the string into DateTime.
string weekEndDate = "20/05/2016";
DateTime EndDate = DateTime.ParseExact(weekEndDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
Or you can use TryParseExact it will not throw exception if string is not parsed into DateTime
DateTime.TryParseExact(weekEndDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None, out EndDate);
Use TryParseExact
string d1 = "11/18/2016 11:45:44 AM";
string d2 = "11/18/2016 11:45:59 AM";
DateTime frmdate;
DateTime todate;
CultureInfo enUS = new CultureInfo("en-US");
bool f = DateTime.TryParseExact(d1, "M/dd/yyyy HH:mm:ss tt", enUS, DateTimeStyles.None, out frmdate);
bool t = DateTime.TryParseExact(d2, "M/dd/yyyy HH:mm:ss tt", enUS, DateTimeStyles.None, out todate);
TimeSpan val = frmdate - todate;
I'm in Asp.net MVC3 environment, and I use Advantage Database 9.1.
and I want to get the Advantage Database data in Asp.net (+Repository pattern)
My Advantage Database has WebOrderHd table and I want to get the PK field of the table and count it.
(Table Name : WebOrderHd Field Name : PK (character(36))
I think I connect to DB server successfully but I can not get the data.
here is my codes,
Web.config
<add name="EFAdsContext" connectionString="Data Source=\\XXX.XX.XX.XX:6262\DB_BACK\SD.ADD;ServerType=REMOTE;User ID=AdsSys;Password=xxxxx"
providerName="Advantage.Data.Provider" />
/Concrete/EFAdsContext.cs
public class EFAdsContext : DbContext
{
public DbSet<WebOrderHd> weborderhd { get; set; }
}
/Concrete/EFWebOrderHdRepository.cs
public class EFWebOrderHdRepository : IWebOrderHdRepository
{
private EFAdsContext context = new EFAdsContext();
public IQueryable<WebOrderHd> WebOrderHd
{
get { return context.weborderhd; }
}
}
/Abstract/IWebOrderHdRepository.cs
public interface IXcartOrdersRepository
{
IQueryable<XcartOrder> XcartOrders { get; }
}
/Entities/WebOrderHd.cs
public class WebOrderHd
{
[Key]
public string PK { get; set; }
//public string ORDERNO { get; set; }
}
And In my controller,
IWebOrderHdRepository WebOrderHdRepository = new EFWebOrderHdRepository();
int adsOrderCnt = WebOrderHdRepository.WebOrderHd.Count();
When run above code, an error occur :
The given key was not present in the dictionary.
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.
Exception Details: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
I guessed the error message say Asp.net can not find the PK field in WebOrderHd table,
but I am sure there is PK field.
Anybody know what I am doing wrong?
Thank You!
Stack Trace :
[KeyNotFoundException: The given key was not present in the dictionary.]
System.Collections.Generic.Dictionary`2.get_Item(TKey key) +9619597
Advantage.Data.Provider.AdsProviderManifest.GetStoreType(TypeUsage edmType) +2930
System.Data.Entity.ModelConfiguration.Edm.Services.StructuralTypeMappingGenerator.MapTableColumn(EdmProperty property, DbTableColumnMetadata tableColumnMetadata, Boolean isInstancePropertyOnDerivedType, Boolean isKeyProperty) +60
System.Data.Entity.ModelConfiguration.Edm.Services.PropertyMappingGenerator.Generate(EdmEntityType entityType, IEnumerable`1 properties, DbEntitySetMapping entitySetMapping, DbEntityTypeMappingFragment entityTypeMappingFragment, IList`1 propertyPath, Boolean createNewColumn) +1293
System.Data.Entity.ModelConfiguration.Edm.Services.EntityTypeMappingGenerator.Generate(EdmEntityType entityType, DbDatabaseMapping databaseMapping) +496
System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.GenerateEntityTypes(EdmModel model, DbDatabaseMapping databaseMapping) +122
System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.Generate(EdmModel model) +30
System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) +189
System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +59
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +62
System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +117
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +453
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +18
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +57
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +37
System.Linq.Queryable.Count(IQueryable`1 source) +50
SportsStore.WebUI.Controllers.ProductController.List(String category, Int32 page) in C:\Users\mark\documents\visual studio 2010\Projects\SportsStore\SportsStore.WebUI\Controllers\ProductController.cs:37
lambda_method(Closure , ControllerBase , Object[] ) +151
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8969117
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
Table Structure
CREATE TABLE WEBORDERHD (
PICKNO Char( 9 ),
STATION Char( 10 ),
CUSTNO Char( 32 ),
COMPANY Char( 35 ),
BNAME Char( 255 ),
ADDRESS1 Char( 30 ),
ADDRESS2 Char( 30 ),
CITY Char( 64 ),
STATE Char( 2 ),
ZIP Char( 10 ),
SCOMPANY Char( 35 ),
SNAME Char( 255 ),
SADDRESS1 Char( 30 ),
SADDRESS2 Char( 30 ),
SCITY Char( 64 ),
SSTATE Char( 2 ),
SZIP Char( 10 ),
SALESPN Char( 10 ),
TAXRATE Numeric( 6 ,3 ),
CERTIFICA Char( 10 ),
TOTAL Numeric( 11 ,2 ),
CONTACT Char( 15 ),
TITLE Char( 10 ),
PHONE Char( 17 ),
FAX Char( 17 ),
BEEPER Char( 17 ),
FREIGHT Numeric( 11 ,2 ),
FINVNO Char( 6 ),
CUSTNOTE Memo,
MEMO Memo,
MODDATE Date,
PRNDATE Date,
SHIPVIA Char( 15 ),
SHIPDATE Date,
DATE Date,
STATUS Char( 30 ),
EMAIL Char( 128 ),
TAX Numeric( 11 ,2 ),
PAYTYPE Char( 20 ),
PAYREF Char( 20 ),
CCREF Char( 50 ),
PK Char( 36 ),
ORDTIME Char( 8 ),
SHIPMETHOD Char( 30 ),
PROCSTATUS Char( 20 ),
CUSTOMERPONO Char( 50 ),
CUSTOMERJOBNO Char( 50 ),
CUSTOMERPOCONTACT Char( 50 ),
CUSTOMERPOCOMMENT Memo,
S_COUNTRY Char( 10 ),
B_COUNTRY Char( 10 ),
SHIPBRANCH Char( 3 )) IN DATABASE;
I by no means am an expert at EF but... have you tried making the PK property virtual? My understanding is EF needs to create a proxy with your models so they have to be virtual so it can implement it the way it needs.
[Key]
public virtual string PK { get; set; }
Also, I would recommend trying to access the data without an advanced pattern first that way you can verify the basics work. I always add a separate console project and test things in there as you don't have to create a whole page just to see the results.
Here is the code:
protected void Button11_Click(object sender, EventArgs e)
{
String usr = Membership.GetUser(false).ToString();
int x, count = 0, avail_shares,num;
float t_c, c_p, c_t,ret,com,t_r,pr;
String comp = this.DropDownList4.SelectedValue.ToString();
avail_shares = Convert.ToInt32(this.TextBox10.Text);
pr = float.Parse(this.TextBox15.Text);
t_c = float.Parse(this.TextBox14.Text);
c_p = float.Parse(this.TextBox12.Text);
c_t = float.Parse(this.TextBox131.Text);
ret = float.Parse(this.TextBox132.Text);
com = float.Parse(this.TextBox133.Text);
t_r = float.Parse(this.TextBox13.Text);
num = Convert.ToInt32(this.TextBox11.Text);
if (num > avail_shares)
{
this.Label23.Text = "You cannot sell more number of shares than what you actuall have";
}
else
{
DbProviderFactory dbproviderfactory = DbProviderFactories.GetFactory("System.Data.SqlClient");
using (DbConnection conn = dbproviderfactory.CreateConnection())
{
string s = ConfigurationManager.ConnectionStrings["Project_FinanceConnectionString"].ConnectionString;
conn.ConnectionString = s;
conn.Open();
DbCommand cmd = conn.CreateCommand();
//DbCommand cmd1 = conn.CreateCommand();
cmd.CommandText = "INSERT INTO sell_activity(username,company,avail_units,old_price,total_old_price,new_price,total_new_price,number,ret,commission,total_return,timestamp)VALUES(#U,#C,#A_U,#O_P,#T_O_P,#N_P,#T_N_P,#N,#R,#C,#T_R,#T)";
//cmd1.CommandText = "SELECT EventID from EventsTable where EventName = ename";
SqlParameter U = new SqlParameter("#U", SqlDbType.NVarChar, 256);
SqlParameter C = new SqlParameter("#C", SqlDbType.NVarChar, 50);
SqlParameter A_U = new SqlParameter("#A_U", SqlDbType.Int);
SqlParameter O_P = new SqlParameter("#O_P", SqlDbType.Float);
SqlParameter T_O_P = new SqlParameter("#T_O_P", SqlDbType.Float);
SqlParameter N_P = new SqlParameter("#N_P", SqlDbType.Float);
SqlParameter T_N_P = new SqlParameter("#T_N_P", SqlDbType.Float);
SqlParameter N = new SqlParameter("#N", SqlDbType.Int);
SqlParameter R = new SqlParameter("#R", SqlDbType.Float);
SqlParameter Commi = new SqlParameter("#Commi", SqlDbType.Float);
SqlParameter T_R = new SqlParameter("#T_R", SqlDbType.Float);
SqlParameter T = new SqlParameter("#T", SqlDbType.DateTime);
U.Value = usr;
C.Value = comp;
A_U.Value = avail_shares;
O_P = pr;
T_O_P = t_c;
N_P=c_p;
T_N_P = c_t;
N = num;
R = ret;
Commi = com;
T_R = t_r;
T = DateTime.Now;
cmd.Parameters.Add(#U);
cmd.Parameters.Add(#C);
cmd.Parameters.Add(#A_U);
cmd.Parameters.Add(#O_P);
cmd.Parameters.Add(#T_O_P);
cmd.Parameters.Add(#N_P);
cmd.Parameters.Add(#T_N_P);
cmd.Parameters.Add(#N);
cmd.Parameters.Add(#R);
cmd.Parameters.Add(#Commi);
cmd.Parameters.Add(#T_R);
cmd.Parameters.Add(#T);
[b]DbDataReader reader = cmd.ExecuteReader();[/b]
try
{
if (reader.HasRows)
{
while (reader.Read())
{
}
}
}
catch (Exception err)
{
Response.Write("Problem in retriving the latest values..Please try again.");
Response.Write(err);
}
reader.Close();
}
}
}
After I try to test the page, I am getting the following error:
System.Data.SqlClient.SqlException: [b]Error converting data type
nvarchar to float. [/b] at
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection) at
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior
runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() at
System.Data.SqlClient.SqlDataReader.get_MetaData() at
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,
RunBehavior runBehavior, String resetOptionsString) at
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
async) at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method, DbAsyncResult result) at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method) at
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
behavior, String method) at
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior
behavior) at System.Data.Common.DbCommand.ExecuteReader() at
portfolio.Button11_Click(Object sender, EventArgs e) in e:\Study\LAST
SEM\Project\Backup\Finance1\portfolio.aspx.cs:line 1187
Any idea guys..
I also tried to debug using watch and every variable is getting the value which it shd get..so I dont get the cause of the problem :(
pl help me out
The ExecuteReader method is usually used for getting the query (SELECT) results as a DataReader object. But I see that you are trying to perform an insert. I suggest to use SqlCommand.ExecuteNonQuery instead and see if it works.
More exactly replace
DbDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
}
}
with
cmd.ExecuteNonQuery();
Also check if any of the SqlParameters that you create with the SqlDbType.NVarChar type maps to a column of type float in the database. Use appropriate types for the SqlParameters.