Why the following code produces the error?
The query operator 'ElementAtOrDefault' is not supported
Dim Im = (From view In Db.Views Where _
view.Pass = txtCode.Text _
Select New With {.Id = view.UniqueID.ToString}_
).Distinct
Response.Redirect("~/test.aspx?x=" & Im(0).Id)
Is there any way of fixing it without using the FirstOrDefault option?
UPDATE: And here is the StackTrace
at System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(Expression node)
at System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.ElementAtOrDefault[TSource](IQueryable`1 source, Int32 index)
at Login.btnLogin_Click(Object sender, EventArgs e) in D:\Projects\Memoria\Login.aspx.vb:line 14
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
What you need to do is add .ToList() to the end of your query. This should work:
Dim Im = (From view In Db.Views Where _
view.Pass = txtCode.Text _
Select New With {.Id = view.UniqueID.ToString}_
).Distinct.ToList()
Response.Redirect("~/test.aspx?x=" & Im(0).Id)
Without .ToList(), the query just returns a DataQuery(Of T) instead of a List(Of T). Adding the ToList call does two things:
Forces the query to execute immediately, and
Returns a collection type that supports ElementAtOrDefault()
Hope that helps!
Related
i have some problems with use the Oracle.ManagedDataAccess.Client.
i use this dll to seach a table, the result is ok. After the table field changes ( for example to add a field or change field type) then the search is error.
this is case:
asp.net code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Oracle.ManagedDataAccess.Client;
public partial class ptest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
using (OracleConnection connection = new OracleConnection(Common.connstr))
{
connection.Open();
OracleCommand cmd = new OracleCommand("select * from v_tmp ", connection);
OracleDataAdapter sa = new OracleDataAdapter(cmd);
DataTable dt = new DataTable();
sa.Fill(dt);
cmd.Parameters.Clear();
Response.Write(dt.Rows.Count.ToString());
}
}
}
the view v_tmp code
create or replace view v_tmp as
select 1 a,2 b from dual
first run is ok , when i change the view v_tmp, add field or change field then display error 。 must reboot iis then ok.
for example
create or replace view v_tmp as
select 1 a,2 b ,1 c from dual
create or replace view v_tmp as
select sysdate a,2 b from dual
the error display
[Exception: Internal Error]
OracleInternal.TTC.TTCExecuteSql.ReceiveExecuteResponse(Accessor[]& defineAccessors, Accessor[] bindAccessors, Boolean bHasReturningParams, SQLMetaData& sqlMetaData, SqlStatementType statementType, Int64 noOfRowsFetchedLastTime, Int32 noOfRowsToFetch, Int32& noOfRowsFetched, Int64& queryId, Int32 longFetchSize, Int64 initialLOBFetchSize, Int64[] scnFromExecution, Boolean bAllInputBinds, Int32 arrayBindCount, DataUnmarshaller& dataUnmarshaller, MarshalBindParameterValueHelper& marshalBindParamsHelper, Int64[]& rowsAffectedByArrayBind, Boolean bDefineDone, Boolean& bMoreThanOneRowAffectedByDmlWithRetClause, List`1& implicitRSList, Boolean bLOBArrayFetchRequired) +3285
OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteReader(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, OracleDataReaderImpl& rdrImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[] scnForExecution, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Int64& internalInitialLOBFS, OracleException& exceptionForArrayBindDML, Boolean isDescribeOnly, Boolean isFromEF) +14144
Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior) +2978
Oracle.ManagedDataAccess.Client.OracleDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +344
System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +108
ptest.Button1_Click(Object sender, EventArgs e) in e:\job\MobileSupport4.0\Web\ptest.aspx.cs:24
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 the bug or the use Configuration issues, if it is how the configuration changes.
I'm trying to get the .NET client library code samples to return a criteria performance report but can't get the code to function. I'm getting an error when clicking the "Download Criteria Report button" on the AdWords.Examples.CSharp.OAuth test page.
The error is as following:
System.Net.HttpWebRequest.GetResponse() +1399
Google.Api.Ads.AdWords.Util.Reports.ReportUtilities.DownloadReport(String downloadUrl, String postBody) in C:\Development\Projects\google.adwords.api\src\AdWords\Util\Reports\New\ReportUtilities.cs:183
[AdWordsReportsException: AdWordsReportsException: One or more AdWords Report download errors have occurred.
ReportDownloadError.INVALID_VERSION. (Error: ReportDownloadError.INVALID_VERSION, FieldPath: , Trigger: )]
Google.Api.Ads.AdWords.Util.Reports.ReportUtilities.DownloadReport(String downloadUrl, String postBody) in C:\Development\Projects\google.adwords.api\src\AdWords\Util\Reports\New\ReportUtilities.cs:204
Google.Api.Ads.AdWords.Util.Reports.ReportUtilities.GetReport() in C:\Development\Projects\google.adwords.api\src\AdWords\Util\Reports\New\ReportUtilities.cs:166
Google.Api.Ads.Common.Util.Reports.AdsReportUtilities.GetResponse() in C:\Development\Projects\google.adwords.api\src\Common\Util\Reports\AdsReportUtilities.cs:162
Google.Api.Ads.AdWords.Util.Reports.ReportUtilities.GetResponse() in C:\Development\Projects\google.adwords.api\src\AdWords\Util\Reports\New\ReportUtilities.cs:310
Google.Api.Ads.AdWords.Examples.CSharp.OAuth.Default.OnDownloadReportButtonClick(Object sender, EventArgs eventArgs) in C:\Development\Projects\google.adwords.api\examples\AdWords\csharp\oauth\Default.aspx.cs:100
[ApplicationException: Failed to download report.]
Google.Api.Ads.AdWords.Examples.CSharp.OAuth.Default.OnDownloadReportButtonClick(Object sender, EventArgs eventArgs) in C:\Development\Projects\google.adwords.api\examples\AdWords\csharp\oauth\Default.aspx.cs:104
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9712662
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204
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) +1639
What am i missing or doing wrong?
My main goal is to retrieve an XML feed that i can display on a webpage.
Any clues ?
which version are you using?
if you are using old version, update them.
Here is Deprecation Schedule.
https://developers.google.com/adwords/api/docs/sunset-dates
My pc windows 2012 server, 64 bit and oracle 12 c client is 32 bit. I am also using IIS. All options are done. I can access my web applications and getting data from database.
However, when I try to add something to database, it is giving error. It is not about tnsnames, connectionstring. The error is:
Exception Details: Oracle.DataAccess.Client.OracleException:
Source Error:
An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[OracleException (0x80004005)] Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck, Int32 isRecoverable) +1508
Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src) +51
Oracle.DataAccess.Client.OracleConnection.Open() +5235
BMS.WebForm1.Button1_Click(Object sender, EventArgs e) +92
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9615682
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
Here is the Connection code
using Oracle.DataAccess.Client;
. . . . .
string oradb = "DATA SOURCE=bms;PASSWORD=training;USER ID=training;";
OracleConnection con = new OracleConnection(oradb);
con.Open();
MyMessageBox("connected!");
con.Close();
I want to run an if before updating a form view;
if yes then..."message" & cancel update query
if no continue update query.
i've tried this but i'm getting a "obeject instance not set to null instance......" on the first line of the if? and the item updates regardless
Private Sub FormView2_ItemUpdating(sender As Object, e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles FormView2.ItemUpdating
Dim status As TextBox = FormView1.FindControl("ApprovalStatusTextBox")
If status.Text = "approved" Or "denied" Then
e.Cancel = True
lblupdaterequest.Text = "you cannot update this request as it has already been responded to"
Else
HolidayDetailsdatasource.Update()
End If
Anyone aware of a better was of achieving something like this?
exact error:
System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
Source=WebApplication1
StackTrace:
at WebApplication1.HolidayApprovalDetails.DetailsView1_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e) in line 32
at System.Web.UI.WebControls.DetailsView.OnItemUpdating(DetailsViewUpdateEventArgs e)
at System.Web.UI.WebControls.DetailsView.HandleUpdate(String commandArg, Boolean causesValidation)
at System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
at System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
I can at least see that you are retrieving the value of the status TextBox from 'FormView1', while your sub ItemUpdating is referring to 'FormView2'.
After changing this, try adding a message box before the if, to make sure you got the right value you wanted:
MsgBox(status.Text)
Hopefully, it helps you solve your problem.
If status IsNot Nothing AndAlso (status.Text = "approved" OrElse status.Text = "denied") Then
I have a Linq-to-SQL data model that includes a type Party which is sub classed twice for Company and Individual. I am trying to bind two repeaters to Linq-to-SQL queries as follows
Dim oComp As IEnumerable(Of Company)
Dim oInd As IEnumerable(Of Individual)
oComp = From oP As Company In ERM.Parties _
Where TypeOf (oP) Is Company And _
oP.Name.StartsWith(sSearchString)
oInd = From oP As Individual In ERM.Parties _
Where TypeOf (oP) Is Individual And _
(oP.FirstName.StartsWith(sSearchString) Or _
oP.LastName.StartsWith(sSearchString))
rptIndividuals.DataSource = oInd
rptCompanies.DataSource = oComp
rptCompanies.DataBind()
rptIndividuals.DataBind()
when I step through the code oComp and oInd are IEnumerable<Company> and IEnumerable<Individual> as expected, but I get the following exception when the first DataBind call is reached
System.MissingMethodException was unhandled by user code
Message="Constructor on type 'System.Data.Linq.Provider.DataBindingList1[[DataModel.Party, DataModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' not found."
Source="mscorlib"
StackTrace:
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Data.Linq.Provider.BindingList.Create[T](DataContext context, IEnumerable1 sequence)
at System.Data.Linq.DataQuery1.GetNewBindingList()
at System.Data.Linq.DataQuery1.System.ComponentModel.IListSource.GetList()
at System.Web.UI.DataSourceHelper.GetResolvedDataSource(Object dataSource, String dataMember)
at System.Web.UI.WebControls.ReadOnlyDataSource.System.Web.UI.IDataSource.GetView(String viewName)
at System.Web.UI.WebControls.Repeater.ConnectToDataSourceView()
at System.Web.UI.WebControls.Repeater.GetData()
at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.Repeater.DataBind()
at parties.lbHiddenPostback_Click(Object sender, EventArgs e) in \parties.aspx.vb:line 491
at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
if I then select everything as parties instead as follows, it all works ok
Dim oComp As IEnumerable(Of Party)
Dim oInd As IEnumerable(Of Party)
oComp = From oP In ERM.Parties _
Where TypeOf (oP) Is Company And _
CType(oP, Company).Name.StartsWith(sSearchString)
oInd = From oP In ERM.Parties _
Where TypeOf (oP) Is Individual And _
(CType(oP, Individual).FirstName.StartsWith(sSearchString) Or _
CType(oP, Individual).LastName.StartsWith(sSearchString))
rptIndividuals.DataSource = oInd
rptCompanies.DataSource = oComp
rptCompanies.DataBind()
rptIndividuals.DataBind()
There is nothing in either repeater that relates to the data returned yet, just a label in the item template to show me how many records are returned for each query.
It doesn't make sense to me that I have to bind to the parent type, I will be unable to access the attributes associated with Individual and Company without first casting to this type!
You can fix this by using .ToArray () when you're setting the DataSource property of the repeater...
rptCompanies.DataSource = oComp.ToArray ()
I'm not convinced I know why it works - but I tried it and it appears to solve the problem!