Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void SaveMact(string ComboxSelectedValue)
        {
            if (MessageBox.Show("You are about to save current operation. Do you want to proceed?", "Save Data", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
                return;
            try
            {
                using (SqlConnection conn = new SqlConnection(GlobalClass.DataConnectionString))
                using (SqlCommand cmdsave = new SqlCommand())
                {
                    conn.Open();
                    cmdsave.Connection = conn;

                    foreach (Menuitem mi in oMenuitemlist)
                    {

                        if (mi.RowChanged > 0 )
                          {
                              cmdsave.CommandText = "UPDATE MENUITEM SET MCAT = @MCAT WHERE MCODE = @MCODE OR PARENT = @MCODE OR MGROUP=@MCODE;
                            cmdsave.Parameters.AddWithValue(@MCAT, mi.Mcat);
                            cmdsave.Parameters.AddWithValue(@MCODE, mi.Mcode);
                            cmdsave.ExecuteNonQuery();

}
}
Posted
Updated 17-Nov-15 17:57pm
v2
Comments
PIEBALDconsult 17-Nov-15 23:58pm    
It looks like you're missing a closing quote.
Other than that, I have no idea what your problem might be. Please use Improve question to add context and detail.
And avoid recursion.
Patrice T 18-Nov-15 0:03am    
The title do not make sense.
details needed
Member 12033805 18-Nov-15 0:24am    
In above code data update from grid view in the relation of parent and child.in above code my problem is only parent and child updated but sub parent and child not update. Row change is the flag 0 and 1 if 1 get data update in database.

Never a good idea to use recursion with the database.

Its better to build a single query to update all records rather than update recursively.
 
Share this answer
 
Comments
Member 12033805 18-Nov-15 0:43am    
In above code data update from grid view in the relation of parent and child.in above code my problem is only parent and child updated but sub parent and child not update. Row change is the flag 0 and 1 if 1 get data update in database.1 value get only top parent but change sub parent top parent row change value o so loop dos not enter the row change>0 so data not update in databse
Abhinav S 18-Nov-15 1:20am    
Can you check if the update query works in sql server?
public void ExecuteSave(object obj)
{
SqlTransaction Tran;
if (MessageBox.Show("You are about to save current operation. Do you want to proceed?", "Save Data";, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
return;
try
{
using (SqlConnection Conn = new SqlConnection(GlobalClass.DataConnectionString))
using (SqlCommand cmd = Conn.CreateCommand())
{
Conn.Open();
Tran = Conn.BeginTransaction();
cmd.Transaction = Tran;
try
{
SaveMCAT(oMenuitemlist, cmd);
Tran.Commit();
}
catch (Exception)
{
if (Tran.Connection != null)
Tran.Rollback();
throw;
}
}
}
catch (Exception)
{

throw;
}
MessageBox.Show("Category Mapped Sucessfully", "Alert")
}

private void SaveMCAT(ObservableCollection<menuitem>, SubGroup, SqlCommand cmdsave)
{
foreach (Menuitem mi in SubGroup)
{
if (mi.RowChanged > 0)
{
cmdsave.CommandText = "UPDATE MENUITEM SET MCAT = @MCAT WHERE MCODE = @MCODE OR PARENT = @MCODE OR MGROUP=@MCODE";
cmdsave.Parameters.AddWithValue(@MCAT;, mi.Mcat);
cmdsave.Parameters.AddWithValue(@MCODE, mi.Mcode);
cmdsave.ExecuteNonQuery();

cmdsave.Parameters.Clear();

}
if (IsCheackedNonTree == true)
{

}
else
{
if (mi.Children.Count> 0)
{
SaveMCAT(mi.Children, cmdsave);
}
}

}

}
 
Share this answer
 
Comments
Member 12033805 18-Nov-15 4:46am    
work this code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900