DataSource Controls :: EntityDataSource Throw Exception When Update With Self-Reference?

Nov 3, 2010

For a Table A defined in the DB like this:

A :{ id, selfId, name,} where selfId is a foreign key refered to Table A itself.

I generated the Entity automatically like this:

A :{ string id; A self; string name,} when i update the entity in gridview Edit/Update CommandField

i got the exception:

Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error:

[Code]....

Stack Trace:

[Code]....

I guess maybe this is caused by:

A is to be updated, and when the EntityDataSource construct the new A, the reference "self" is invalid at that moment. I do not want to modify my DB structure and do not want to lose the self reference, The event EntityDataSource_Updating is not triggered while the exception hit. so i can not access my entity at any time. Maybe the worst idea is deal the whole Update Procedure myself. However, is there any better workaround?

View 3 Replies


Similar Messages:

Set Dynamic Controls So It Doesn't Throw Exception

Jun 28, 2010

I have problem with Dynamic Controls in my Wizard Steps. In one of my Steps, I create a set of text boxes and checkboxes based on values from an XML document. Now, I initialise my dynamic controls using the OnInit method of the page, but at this stage there is no xml document until that step is reached, and of course I get null exception. How do I set my dynamic controls so it doesn't throw an null exception and be able to load any xml document when that step is reached?

View 1 Replies

Forms Data Controls :: Throw The Exception Back To Page_Load Error: ArgumentNullException Was Unhandled By User Code

Nov 19, 2010

I'm trying to throw the exception back to Page_Load but the throw statement causes error: ArgumentNullException was unhandled by user code. How can that be fixed? Also, I can't see Label1.Text displayed on the page after the ArgumentNullException occurs because the page is not re-load. If there is no exception, it's fine to not reload the page. How can I see the Label1.Text displayed?

protected void Page_Load(object sender, EventArgs e)
{
try
{
...do something here...
}
catch (ArgumentNullException ae)
{
System.Diagnostics.Debug.Write(ae.Message);
Label1.Text = ae.Message;
Label1.Style.Add("visibility", "visible");
}
catch (Exception ex)
{
...do something here...
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)............................

View 3 Replies

How To Throw And Catch Exception Handling

Oct 12, 2010

iam inserting record in three tables in a database, iam using begin trans , commit transaction and rollback,

i want to use throw method, if any value insert wrong, pls correct me, i want to throw the error and

its go to rollback

running = false;
int updaterec = DBmgr.ExecuteNonQuery(CommandType.Text, "update ASArrivedcontainer set billgen ='Y' where billgen ='y' and acontinerid in ("+SelValues+")");
if (updaterec > 0)
{
running = true;
DataSet BillContainerDetails = BillingDetails();
byte[] ContainerDetails = GenerateBill(DBmgr, sContainerIds, rcno,isGeneralRCNo, FetchContainerDetails, ModifyId,ref BillContainerDetails);
DBmgr.CreateParameters(6);
//string otherchargesId = obj.retriveSingleRecord("select top(1) ModifyId from ASOtherCharges");
DBmgr.AddParameters(0, "@InvoiceNo", "1","IN");
DBmgr.AddParameters(1, "@BillDate", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss tt"), "IN");
DBmgr.AddParameters(2, "@CustomerId", "1", "IN");
DBmgr.AddParameters(3, "@TotalAmount", "10000", "IN");
DBmgr.AddParameters(4, "@OtherChargesId", ModifyId, "IN");
DBmgr.AddParameters(5, "@ContainerDetails", ContainerDetails, "IN");
String BillNo = DBmgr.ExecuteScalar (CommandType.Text, "Insert into BillMaster(InvoiveNo,BillDate,CustomerId,TotalAmount,OtherChargesId,ContainerDetails) values (@InvoiceNo,@BillDate,@CustomerId,@TotalAmount,@OtherChargesId,@ContainerDetails)
Select @@Identity ").ToString();
if (!String.IsNullOrEmpty(BillNo))
{
running = true;
DBmgr.CreateParameters(4);
for (int i = 0; i < BillContainerDetails.Tables[0].Rows.Count; i++)
{
BillContainerDetails.Tables[0].Rows[i]["BillNo"] = BillNo;
DBmgr.AddParameters(0, "@Billno", BillContainerDetails.Tables[0].Rows[i].ItemArray[1].ToString(), "IN");
DBmgr.AddParameters(1, "@rcno", BillContainerDetails.Tables[0].Rows[i].ItemArray[2].ToString(), "IN");
DBmgr.AddParameters(2, "@acontinerid", BillContainerDetails.Tables[0].Rows[i].ItemArray[3].ToString(), "IN");
DBmgr.AddParameters(3, "@bflag", BillContainerDetails.Tables[0].Rows[i].ItemArray[4].ToString(), "IN");
//string value = BillContainerDetails.Tables[0].Rows[i].ItemArray[0].ToString(); ;
// string strsql = "insert into billcontinerdetail(billno,rcno,acontinerid,bflag) values(@billno,@rcno,@acontinerid,@bflag)";
String count = DBmgr.ExecuteScalar(CommandType.Text, "insert into billcontinerdetail(billno,rcno,acontinerid,bflag) values(@billno,@rcno,@acontinerid,@bflag)Select @@Identity").ToString();
if (count > 1)
{
running = true;
}
else
{
}
//running = true ;
//break;
}
DBmgr.CreateParameters(6);
for (int j = 0; j < BillContainerDetails.Tables[1].Rows.Count; j++)
{
DBmgr.AddParameters(0, "@billcontkey", BillContainerDetails.Tables[1].Rows[j].ItemArray[1].ToString(), "IN");
DBmgr.AddParameters(1, "@ratetypcode", BillContainerDetails.Tables[1].Rows[j].ItemArray[2].ToString(), "IN");
DBmgr.AddParameters(2, "@days", BillContainerDetails.Tables[1].Rows[j].ItemArray[3].ToString(), "IN");
DBmgr.AddParameters(3, "@amount", BillContainerDetails.Tables[1].Rows[j].ItemArray[4].ToString(), "IN");
DBmgr.AddParameters(4, "@level", BillContainerDetails.Tables[1].Rows[j].ItemArray[5].ToString(), "IN");
DBmgr.AddParameters(5, "@sflag", BillContainerDetails.Tables[1].Rows[j].ItemArray[6].ToString(), "IN");
// string strsql = "insert into billratedetail(billcontkey,ratetypcode,days,amount,level,sflag)values(@billcontkey,@ratetypcode,@days,@amount,@level,@sflag)";
String count = DBmgr.ExecuteScalar(CommandType.Text, "insert into billratedetail(billcontkey,ratetypcode,days,amount,level,sflag)values(@billcontkey,@ratetypcode,@days,@amount,@level,@sflag)Select @@identity ").ToString()
;

View 2 Replies

Global.Asax - When Click On Datagrid Throw Exception

Nov 4, 2010

I m having a datagrid and for client side events I m using Javascript. I have few other buttons in the same page.

when I click on datagrid and select, it is working fine. After that, if I click on any other button in the Page, It is directly going to global.asax and throwing exception.

If I click directly on other buttons, they are working fine. Once I click on Datagrid and try to click on other buttons, it is throwing that exception.

View 2 Replies

How To Throw Exception If Session Is Written To In ReadOnly Mode

Sep 3, 2010

I would like to find a way to raise an exception if the Session is written to when in readonly mode. When EnableSessionState is set to "ReadOnly", values can still be put in Session, but the next request they will not be there. This seems somewhat dangerous.

One option is to create a helper class which we alway use to access session. However, this still leaves room for a developer to inadvertently use session directly, and fall into the "readonly" trap. Is there a way to create a CustomSessionStateDataStore that sits on top of the existing session code? I could not see an obvious way, and you can't inherit from System.Web.SessionState.SessionStateStoreData directly.

View 2 Replies

Web Forms :: DataSet.Fill Takes Along Time To Throw Exception When Connectionstring Wrong

Jan 18, 2010

when my website allow user many connectionstring by text to connect database anh retrieve data. But when user define very may wrong connectionstring. So Method in DAL dataset.Fill() takes a longtime to throw exception.So mywebsite will be die.

I want to method dataset.Fill() throws exception immediately when a connectionstring wrong. How can i do that?

View 2 Replies

DataSource Controls :: LinqDataSource And EntityDataSource?

Jun 12, 2010

I'v been using SqlDataSource and ObjectDataSource for a while.I would like to know about LinqDataSource and EntityDataSource. Therefore I have 2 questions to ask.1) Why do we need to use those twos? 2) In which cirmustances (Requirements) developers are using LinqDataSource and EntityDataSource?

View 1 Replies

DataSource Controls :: How To Convert The ESQL For EntityDatasource

Mar 11, 2011

T-SQL

[Code]....

And i want to convert to eSQL for EntityDatasource

[Code]....

But it is error.

View 1 Replies

DataSource Controls :: Passing A Value From ListView To EntityDataSource?

Jan 24, 2011

I have this code, and I need the "it.MembershipOption.Id" value in the "where" clause to be the <%# Eval("Id") %> from ListViewEventsOuter. I tried to add the Eval in the "where" clause but it throws an error.


How is this done?

[code]...

View 1 Replies

DataSource Controls :: Extending The EntityDataSource Control?

Mar 15, 2010

What would be the best way to extend the EntityDataSource control? I have a site that implements Entity Framework and I current create my model container and add it to the HTTPCurrent context. When I create EntityDataSource controls on the page I have to go into the code behind and set the OnContextCreating to add MY context to the EntityDataSource instead of the one that EntityDataSource creates. This is because in my model I have extended the Partial Classes to support Validation and custom Save/Delete methods.I would ideally like to create a custom control that I can drop onto a page that has its context already set to the context that I created.

View 1 Replies

WCF / ASMX :: Call HTTPS Web Reference Through Another Web Reference - An Unhandled Exception Of Type Error?

Aug 6, 2010

I am trying to call web reference "A" in an application.

The web reference "A" will then call a function in another web reference "B" through HTTPS connection (require certificate).

Then I keep getting the following error:

An unhandled exception of type 'System.Web.Services.Protocols.SoapException' occurred in System.Web.Services.dll

View 3 Replies

DataSource Controls :: EntityDataSource Filtering / ESQL Where Clause?

Feb 28, 2010

I have a GridView that's currently bound to an ObjectDataSource. I would like to see if it's possible to instead bind it to an EntityDataSource. However, I need to be able to apply custom filters to it.

One of the filters corresponds to a bit / boolean property in the database / EntityDataModel. It has 3 possible selections:

[Code]....

[code]....

How can I accomplish the same thing in an eSQL Where clause? There is no COALESCE function, is there an equivalent?

View 1 Replies

DataSource Controls :: EntityDataSource With Include For Related Columns

Feb 28, 2011

I have a formview with an entityDataSource. I need to include columns from related fields. I have seen many demos, with AdventureWorksDB, that imply that you can do this by using INCLUDE in the entitydatasource declaration. I have tried made many attempts and it just does not seem to work as demonstrated. I have attached the errors below and the EDS. I have also attached a JPEG of the model I am working in. Three errors demonstrating 3 different attempts to include a related table:

DataBinding: 'TmModel.tbICObjectBase' does not contain a property with the name 'Group'
the code declaration for error 1:
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Group") %>' />
DataBinding: 'TmModel.tbICObjectBase' does not contain a property with the name 'tbICTagBase'.
the code declaration for error 2:
<asp:Label ID="Label1" runat="server" Text='<%# Bind("tbICTagBase.Group") %>' />
DataBinding: 'System.Data.Objects.DataClasses.EntityCollection`1[[TmModel.tbICTagBase, TmModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' does not contain a property with the name 'Group'.
the code declaration for error 3:
<asp:Label ID="tbICTagBasesLabel" runat="server" Text='<%# Bind("tbICTagBases.Group") %>' />
EntityDataSource
<asp:EntityDataSource ID="entDSObjectBase" runat="server" AutoGenerateWhereClause="True"
ConnectionString="name=IntouchDBContainer" Include="tbICTagBases"
DefaultContainerName="IntouchDBContainer" EnableFlattening="False"
EntitySetName="tbICObjectBases" EnableDelete="True" EnableInsert="True"
EnableUpdate="True" EntityTypeFilter="tbICObjectBase">
<WhereParameters>
<asp:SessionParameter SessionField="Tag" Name="RecID" Type="Int64" />
</WhereParameters>
</asp:EntityDataSource>

You can see the model at [URL] Or [URL]

View 3 Replies

DataSource Controls :: OrderBy Parameter Type In EntityDataSource?

Feb 26, 2010

I'm playing with an EntityDataSource and specifying a simple order by clause containing one column name, for instance "it.[DNS_NAME]".

When I run the following:

[Code]....

I get an EntitySqlException saying that @sort's type is incorrect. It is expecting a Transient.rowtype that matches one of the columns. What is going on here? Order by parameters don't really have a meaningful type other than a string in my opinion. When I try specifying DbType.String instead of TypeCode.String, the same error is thrown.

The exception:

'@sort' is not a member of type 'Transient.rowtype[(SOFTWARE_DSPL_ID,Edm.Int32(Nullable=True,DefaultValue=)),(COMPUTER_NAME,Edm.String(Nullable=True,DefaultValue=,MaxLength=64,Unicode=True,FixedLength=False)),(DNS_NAME,Edm.String(Nullable=True,DefaultValue=,MaxLength=64,Unicode=True,FixedLength=False)),(DIRECTORATE_NAME,Edm.String(Nullable=True,DefaultValue=,MaxLength=24,Unicode=True,FixedLength=False)),(OS_BROAD_CAT_NAM,Edm.String(Nullable=True,DefaultValue=,MaxLength=25,Unicode=True,FixedLength=False)),(OS,Edm.String(Nullable=True,DefaultValue=,MaxLength=64,Unicode=True,FixedLength=False)),(EQP_TYPE,Edm.String(Nullable=True,DefaultValue=,MaxLength=64,Unicode=True,FixedLength=False)),(EQP_PROP_NO,Edm.String(Nullable=True,DefaultValue=,MaxLength=10,Unicode=True,FixedLength=False))]'
in the currently loaded schemas.

How can I dynamically provide the column name to order by?

View 9 Replies

DataSource Controls :: Getting Exception / An Exception Occurred While Executing A Transact-SQL Statement Or Batch

Jan 1, 2010

i need to restore Database.mdf; I create a blank new database exactly the same name as the .mdf file. However, I could not restore the database.

The error message prompted was:

TITLE: Microsoft SQL Server Management Studio Express

An exception occurred while executing a Transact-SQL statement or batch.

(Microsoft.SqlServer.Express.ConnectionInfo)

ADDITIONAL INFORMATION:

Cannot open backup device 'C:inetpubwwwrootTCPSystemApp_DataDatabase.mdf'. Operating system error 32(error not found).

RESTORE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3201)

click: [URL]

BUTTONS:

OK

View 10 Replies

Unable To Throw Custom Error Handler From Within An Exception / "UnableToOpenDatabaseException Was Unhandled"

Jul 25, 2010

Why can't I throw a custom exception from within an Exception? In code below, I get error msg "UnableToOpenDatabaseException was unhandled" even though I have catch statement for it. What am I doing wrong? and how to fix it?

[Code]....

View 3 Replies

AJAX :: Throw Exception Message "Authentication Failed" When Call Webservice Form Javascript

Aug 16, 2010

I was created webservice which has a Method:

[Code]....

Then, in my aspx page, i call that method in javascript, but i get a Exception message is "Authentication Failed", code below:

[Code]....

How to resolve this problem?

View 3 Replies

DataSource Controls :: Reference To A Non-shared Member Requires An Object Reference

Apr 22, 2010

I am using VS2005, and a newbie at table adapters, DAL & BLL. I have a single dataset (in DAL) and 2 classes (in BLL) named Class1.vb and Class2.vb.

When I try to call a function from Class1 within Class2 I get the error "Reference to a non-shared member requires an object reference".

Here is a sketch of my code structure:

[Code]....

View 3 Replies

Why Does Custom HttpResponse Throw Exception On HttpResponse.End()

Jul 27, 2010

I'm writing some code in which I need to use my own HttpResponse object to capture the output from a method on another object that takes an HttpResponse as a parameter. The problem is, this other object (which I cannot modify) calls HttpResponse.End(), which causes an "Object reference not set to an instance of an object" exception to be thrown. What can I do about this?

Dim myStringbuilder As New StringBuilder
Dim myStringWriter As New IO.StringWriter(myStringbuilder)
Dim myResponse As New Web.HttpResponse(myStringWriter)

someObject.doStuffWithHttpResponse(myResponse) ' calls myResponse.End() and crashes

Here's some more complete information about the error, thrown from the following code in a console application:

Dim myStringbuilder As New StringBuilder
Dim myStringWriter As New IO.StringWriter(myStringbuilder)
Dim myResponse As New Web.HttpResponse(myStringWriter)
Try
myResponse.End()
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try

Here's the text of the exception:

System.NullReferenceException: Object reference not set to an instance of an object.
at System.Web.HttpResponse.End()
at ConsoleApplication1.Module1.Main() in C:Documents and Settingsjoe.userLocal SettingsApplication DataTemporary ProjectsConsoleApplication1Module1.vb:line 10

View 2 Replies

AJAX :: Update EntityDataSource Through Calendar Extender?

Nov 5, 2010

I use calendar extender with targetID of text box. this text box is used as a parameter in EntityDataSource. now problem is that when i select the date DataSource wasn't updated. i also try it by changing the autopostback property of textbox but after postback no changes occurs and textbox is also initialize to null

now what should i do for that? [:(]

View 3 Replies

Forms Data Controls :: Null Reference Exception Was Not Handled By User?

Sep 2, 2010

Null Reference Exception was not handled by user Object Reference not set to instance of an object

View 2 Replies

Forms Data Controls :: Null Reference Exception In Grid View?

May 19, 2010

i have null reference exception in grid view, in the

string s = ((Label)GridView1.FindControl("Label6")).Text;

i tryed this to e.Values["EventId"].ToString()

but still the some why is that?

the full code :

[Code]....

View 1 Replies

EntityDataSource Null Update Parameters Not Getting Marked Modified

Feb 24, 2011

I am using an EntityDataSource with a FormView on VB.NET application. The FormView contains an AjaxControlToolKit TabContains with multiple tabs. Due to the fact that each tab is a naming container, Bind doesn't work properly for updating values (as discovered from reading other posts on stackoverflow). I instead have to declare UpdateParameters on my EntityDataSource. Example markup is as follows:

<asp:FormView ID="fv" runat="server" DataSourceID="eds" DataKeyNames="ID">
<EditItemTemplate>
<asp:TabContainer ID="tc" runat="server">
<asp:TabPanel ID="tp" runat="server" HeaderText="Tab 1">

[Code]....

This works great, until a customer is edited and their name is set to nothing (assuming in this case, a null name is allowed). The Name UpdateParameter is set to Null but the ObjectStateEntry is not set to modified for Null properties, even if previously the Entity had a value specified. As long as the name is changed to something other than Null, everything is updated correctly.

I found a workaround by putting the following code in the Updating event of the EntityDataSource.

Dim ose As ObjectStateEntry = context.ObjectStateManager.GetObjectStateEntry(action)
For Each p As Parameter In eds.UpdateParameters
ose.SetModifiedProperty(p.Name)
Next

This makes sure that each property in the UpdateParameters has its state set to modified. It works, but it seems like a hack and I can see it causing problems down the road. Is there anything else I could do?

View 1 Replies

Web Forms :: Code-Behind Null Reference Exception Accessing Controls With Derived PageBase?

Feb 16, 2010

I have a class that derives from System.Web.UI.Page and have set my pages to derive from this custom page class instead of Page. At runtime, the controls are never initialized and throw a NullReferenceException. I've changed some class names and namespaces in the pasted code to protect the innocent. The only thing that I currently override in my PageBase is OnPreLoad and I do call the base.OnPreLoad. I'll eventually add more functionality to this PageBase but for now all that it has is this:

[Code]....

I've tried putting this into a class library (with System.Web referenced) and I've also tried moving the class into the web application and had the same results either way. As another strange twist, I have another class with derives from PageBase called IndexPageBase and it doesn't have this problem:

[Code]....

[Code]....

[Code]....

View 7 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved