When I Sort menu: => keep Event:Sorting from Mouse =>
Menu:
Home(1) News(2) About(3) => News(2) Home(1) About(3)
Event will save position to two table at the same time.
I know using Trigger can solve this problem. But structure of two table is different. So, I cannot use Trigger for this.
Now, I want inserting/updating will looks like two table.
table1:
Order
2
1
3
table2:
Order: 213
How can I update/insert for two above tables at the same time.
Tks a lot
This is Event of Sorting for Update to two tables but it seems update to table1
//-------Update for table: Items---------//
command.Connection = connection;
command.CommandText = "UpdateItemsOrder";
command.CommandType = CommandType.StoredProcedure;
SqlParameter paramUserName = new SqlParameter("@ItemOrder", SqlDbType.VarChar, 255);
paramUserName.Value = itemOrder;
command.Parameters.Add(paramUserName);
//----Update for table: NewOrders(get data from column ItemOrder)--//
string username = "aloha";
DemoDataContext dc = new DemoDataContext();
var strJoin= (from m in dc.Items
select m.ItemOrder);
var result = string.Join("", strJoin.Select(x => x.Value).ToArray());
var reUpdateOrder = dc.NewOrders.Single(a => a.UserOrder.Equals(username));
reUpdateOrder.NewItemOrder = result;
dc.SubmitChanges();
connection.Open();
return (command.ExecuteNonQuery() > 0);
It inserts only to table:Items, not get data from Items at that time to update for table:NewOrders.
Connection always open for Sorting.
Please help me.
This is just a guess, but it looks as though
NewOrdersmay not have a primary key established..? You may be able to select orders by username, but without a primary key, LINQ-to-SQL won’t know how to find update the record upon callingdc.SubmitChanges();Also, is there any particular reason you are leaving the SqlConnection open for sorting? This can lead to threading issues in some cases and is usually best left to the connection pool to handle.
SubmitChanges()will open it’s own connection, so there’s no need to keep the SqlConnection open for it. You should handle each update separately: