|
|
BETTER U LEAVE THIS FIELD
|
|
|
|
|
Hi All,
I have a C# application, which inserts or updates values in to some tables in the SQL Server Database. As it does line by line, whenever any insert or update fails, we need to rollback all inserted values. Not only from the same table but from all the tables in which the rows are inserted.
Is there any mechanism to implement it from C# code. Even if it SQL Command I dont have any issues but, I should be able to call that command from C# code. Is there any way to implement all this as one transaction in C# code and roll back it. Is it possible to rollback what is inserted in C# code. Please help me out in this issue.
Any links any suggestions would be of great help. Thanks in advance.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
|
Hi,
What I am looking for is, is there any type of Dataset in which I can add all these tables or define schemas, then iserting first in the dataset. If there is any mimatch thorwing the error from there itself only. If every thing goes correct then writing in to the database.
Does this makes sense. If this is possible in .Net please give me your advice. I would appreciate it. Why am I doing this is, instead of writing on to the database and rolling back. Check before inserting in to the database, by filling up the already defined schemas in the dataset. Then if any mismatch occurs log the error and terminate the program or asking user to verify the source database.
Is there any any way tot do this?
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
|
Hi,
I cant use transaction at database side. Passing such a huge data is a network overhead. Let us suppose I have 50 tables, I am using different TableAdapter for different table.
Even if one insertion in one table fails all the 50 tables transaction(insertions or updates) should be rolled back. Again deletion is also not possoble because its overhead on the Database Server.
Can any body help me in this regard. In the above answer, that is maintaining transaction in the application (C# code).
But I am looking for more easier option.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
indian143 wrote: But I am looking for more easier option.
Define "easier"?
Did you even look at the links you were provided?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Yes. I did. Thanks for the help buddy. Easier in the sense some components which can take the transaction within themselves or soemthing like that. But your links are helpfull. Thanks for the help.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
What makes you think deletion is more overhead than rollbacks? Having the server track 50 simultaneous inserts in one transaction is almost certainly more overhead as long as you manage your connections properly and use stored procedures.
If you are inserting into 50 tables at once it really sounds like you need to change your data model. You probably need to denormalize your OLTP data a bit to optimize for inserts.
|
|
|
|
|
Hi,
What I am asking is, is there any dataset or anything like that in which we can store the data before insert and if all goes well, then inserting data in to the Database tables.
Here the condition is, the dataset should be able to handle the datatypes, Foreign, Unique Key and Check constraints properly. Is there any way to do thsi.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
The .Net DataSet object supports defining DataRelations that act like foreign keys. You can add UniqueConstraints and ForeginKeyConstraints. You should browse the docs for the System.Data Namespace[^].
|
|
|
|
|
Can we write text and upload image in the text editor type and save that data in html format ? Any idea if we need to put text plus image together??
suchita
|
|
|
|
|
Hi Suchita,
SayamiSuchi wrote: Can we write text and upload image in the text editor type and save that data in html format ? Any idea if we need to put text plus image together??
Your problem is not clear to me. Could you please explain it in details ?
I am bit confused in this statement,
SayamiSuchi wrote: Can we write text and upload image in the text editor type
And where do you want to save ?
|
|
|
|
|
Sorry for not stating my problem well. Actually I am wondering if we could do something like this.
Lets say I have a text editor and we can get the input data from the text editor. Now Is it possible someway that we can have text and image as a data in that text editor ? Also when we save, Can we save both text and image as a single data and save it ?
suchita
|
|
|
|
|
Which texteditor are you using ? Is it AJAX Text editor ?
|
|
|
|
|
no I am just using textbox setting multiline..
suchita
|
|
|
|
|
You can not do it in multiline textbox.
Consider FCK editor for the same.
You may need to do a bit of struggle to store both Text and Image in binary format.
|
|
|
|
|
thanks. I will try.
suchita
|
|
|
|
|
hello,
I have a table in database which is as below:
CREATE TABLE item(
id INT,
itemModel VARCHAR(100),
name VARCHAR(100),
description VARCHAR(100),
created VARCHAR(100),
creator VARCHAR(100),
then in my BusinessObject Layer I have this class:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.ComponentModel;
namespace WebApplication1.Repository.BusinessObject
{
public class Items
{
private int _id = -1;
private string _model = string.Empty;
private string _name = string.Empty;
private string _description = string.Empty;
private DateTime _created = DateTime.MinValue;
private string _ctreator = string.Empty;
[DataObjectFieldAttribute(true,true,false)]
public int ID
{
set { _id = value; }
get { return _id; }
}
public string Model
{
set { _model = value; }
get { return _model; }
}
public string Name
{
set { _name = value; }
get { return _name; }
}
public string Description
{
set { _description = value; }
get { return _description; }
}
public DateTime Created
{
set { _created = value; }
get { return _created; }
}
public string Creator
{
set { _ctreator = value; }
get { return _ctreator; }
}
public Items(int id, string model, string name, string description,
DateTime created, string ctreator)
{
this._id = id;
this._model = model;
this._name = name;
this._description = description;
this._created = created;
this._ctreator = Creator;
}
}
}
then I create another layer called DataAccess define this class
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using WebApplication1.Repository.BusinessObject;
using System.Data.Common;
using System.Data.SqlClient;
namespace WebApplication1.Repository.DataAccessLayer
{
public class ItemsDB
{
public static int Save(Items NewItems)
{
int Result = 0;
SqlConnection MyConnection = new SqlConnection(ConfigurationManager.
ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand MyCommand = new SqlCommand("SprocInsertUpdateSingleItem",
MyConnection);
MyCommand.CommandType = CommandType.StoredProcedure;
if (NewItems.ID == -1)
{
MyCommand.Parameters.AddWithValue("@id", DBNull.Value);
}
else
{
MyCommand.Parameters.AddWithValue("@id", NewItems.ID);
}
MyCommand.Parameters.AddWithValue("@ItemModel", NewItems.Model);
MyCommand.Parameters.AddWithValue("@Name", NewItems.Name);
MyCommand.Parameters.AddWithValue("@Description", NewItems.Description);
MyCommand.Parameters.AddWithValue("@Created", NewItems.Created);
MyCommand.Parameters.AddWithValue("@Creator", NewItems.Creator);
DbParameter returnValue;
returnValue = MyCommand.CreateParameter();
returnValue.Direction = ParameterDirection.ReturnValue;
MyCommand.Parameters.Add(returnValue);
MyConnection.Open();
MyCommand.ExecuteNonQuery();
Result = Convert.ToInt32(returnValue.Value);
MyConnection.Close();
return Result;
}
}
}
next, in BusinessLogicLayer I try to interact with database
using System;
using System.Collections.Generic;
using System.Web;
using System.ComponentModel;
using System.Transactions;
using WebApplication1.Repository.DataAccessLayer;
using WebApplication1.Repository.BusinessObject;
namespace WebApplication1.Repository.BusinessLayer
{
public class ItemsManager
{
[DataObjectMethod(DataObjectMethodType.Update,true)]
public static int Save(Items NewItem)
{
using (TransactionScope MyTransactioScope = new TransactionScope())
{
int ItemId = ItemsDB.Save(NewItem);
foreach ( Items itemId in NewItem.ID)
{
itemId.ID = ItemId;
ItemsDB.Save(itemId);
}
NewItem.ID = ItemId;
MyTransactioScope.Complete();
return ItemId;
}
}
}
}
after I run the program I get this error:
<br />
foreach statement cannot operate on variables of type 'int' because 'int' does not contain a public definition for 'GetEnumerator' <br />
Do you recken the problem is regarding database design?
I get this idea from the following link
http://www.wewill.cn/n2020c22.aspx
I really appreciate if someone help me in this matter.
is there anyway to put my project here?then people can see it and maybe help me.
|
|
|
|
|
foreach ( Items itemId in NewItem.ID)
{ ... }
2 things are wrong in this case.
1. You are trying to enumerate an integer (which does not implement IEnumerable and does not have to - more info about IEnumerable[^]) that belongs to NewItem object (Items class)
2. NewItem is an instance of Items and thus there is just 1 object. So you need not enmumerate but just replace
foreach ( Items itemId in NewItem.ID)
{
itemId.ID = ItemId;
ItemsDB.Save(itemId);
}
NewItem.ID = ItemId;
with
NewItem.ID = ItemsDB.Save(NewItem);
I didn't go through all of your code, but this will help solve your error.
Cheers,
Karthik
|
|
|
|
|
When developing web page for mobile, what's the standard width I should use?
|
|
|
|
|
There isn't a "standard" width... this[^] site is temporarily down ("scheduled maintenance", it says) but take a look when it's back up.
|
|
|
|
|
Hello All,
I'm using VS 2010 .In this, I have bound the DataSource in the Gridview.I have taken one Button in the HeaderTemplate in the columns in the GridView. Now, I want to add New DataRow with empty textboxes in gridview.
the code is as follows:
<asp:gridview id="grdUserDetails" runat="server" datakeynames="UserId" width="80%"
="" onrowcommand="grdUserDetails_RowCommand" onpageindexchanging="grdUserDetails_PageIndexChanging" onrowcancelingedit="grdUserDetails_RowCancelingEdit" onrowdeleting="grdUserDetails_RowDeleting" onrowediting="grdUserDetails_RowEditing" onrowupdating="grdUserDetails_RowUpdating">
<columns>
<asp:templatefield headertext="Action" itemstyle-width="10%" headerstyle-width="10%">
<headertemplate>
<asp:button id="btnAddNewRow" runat="server" text="Add New Row">;
<itemtemplate>
<asp:linkbutton id="btnEdit" runat="server" causesvalidation="false" commandname="Edit" text="Edit">
<asp:linkbutton id="btnDelete" onclientclick="return confirm('Are you sure you want to delete?');" runat="server" causesvalidation="false" commandname="Delete" text="Delete">
<edititemtemplate>
<asp:linkbutton id="btnUpdate" runat="server" commandname="Update" validationgroup="EditValidation" text="Update">
<asp:linkbutton id="btnCancel" runat="server" causesvalidation="false" commandname="Cancel" text="Cancel">
|
|
|
|
|
Review Code Project guidelines and format any code snippets you post. You will be mostly ignored until you do.
Yo have posted no question. What are you having difficulties with?
I know the language. I've read a book. - _Madmatt
|
|
|
|