Click here to Skip to main content
15,123,679 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a Solution for adding new row directly to datagridview in c#,
but in this solution when i press save button,new row added to database.
How can i do this without any extra button and when i click other row or
add another row my row added automatically.

The Save Button Calls following procedure:
C#
private void AddRowToTable()
       {        
           if (passGrid.Rows[TotRowCount].Cells[1].Value.ToString() != "")
           {
               UserName = passGrid.Rows[TotRowCount].Cells[1].FormattedValue.ToString();
           }
           else {UserName = null; }
           if (passGrid.Rows[TotRowCount].Cells[2].Value.ToString() != "")
           {
               Password = passGrid.Rows[TotRowCount].Cells[2].Value.ToString();
           }
           else { Password = null; }
           try
           {
               var dbCnn = ConnClass.ConDB();
               {
                   PassWord pas = new PassWord();
                   if (UserName != null || Password != null)
                   {
                       pas.UserName = UserName;
                       pas.PassWord1 = Password;
                       dbCnn.GetTable<PassWord>().InsertOnSubmit(pas);
                       dbCnn.SubmitChanges();
                       BindDataGridView();
                       InitRowCount = passGrid.RowCount;
                   }
               }
           }//end try
           catch (Exception ex)
           {
               throw ex;
           }

       }



Where i can write the code of save button?

in which event or code?

Please help me.

Thanks
Posted
Updated 8-Aug-12 0:44am
v2
Comments
   
what code do you have in BindDataGridView() method...

1 solution

I would make the changes on the database, clear the Grid and reload the table. In this way you avoid having a connection open all the time, and is an easy and fast way of modifying a table.
   

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