Posts

Restore database in SQL Server Management Studio from Device

Image
Step 1:   Right click on Databases and select "Restore Database..." Step 2: Select "From device" and then click on that button Step 3: Select Add Step 4:   Select "Files of type" as "All Files(*)" Step 5: Go to the database location and select that database. Then press Ok. Step 6: Press Ok Step 7: Give the database name as you want to save the database.  Mark the Restore box. Press Ok. Step 8: At the end, it will show successful message.

Backup database in SQL Server Management Studio

Image
Step 1:   Open SQL Server Management Studio > Databases Select the database (I select  StudentDB  database) Right click on the database Select Tasks > Back Up. Step 2: Remove the "By default" destination path.   Step 3: Press Add to set the destination path. Step 4: Press the button to select destination path. Step 5: Select your destination path. I select K drive > CodePointProgramming folder. Set the File name. It is a good practice to add current date with the database name while taking backup. For example: StudentDB_27112020 Step 6: Press "Ok" Step 7: Press "Ok". Step 8: At last it will show a success message. 

Button Column Click Event of DataGridView

Image
Suppose, we have two button column in a dataGridView. One is "Edit" and another is "Delete". When "Edit" column's button is pressed, some tasks need to perform. Same goes for "Delete" column's buttons. To do so, select CellContentClick Event of dataGridView. Then do the following code:   private void studentDetailsDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if(e.RowIndex >= 0) // To avoid header of the columns... { if (senderGrid.Columns[e.ColumnIndex] == senderGrid.Columns["nameOfButtonColumn1"]) { } else if (senderGrid.Columns[e.ColumnIndex] == senderGrid.Columns["nameOfButtonColumn2"]) { } } } If you don't know the name of your button column, see  this

Name of the button column in dataGridView

Image
Here I have two button column named Edit and Delete. To get the column's name, do the following steps.  Step 1:  Select the dataGridView and click on the arrow sign. Step 2:  Select the Edit Columns option. Step 3:  On the left side, a list of column's header will be shown of the dataGridView. To change the properties of Edit Column select Edit . On the right side, it's properties will be shown. The Name under Design section indicates the name of the Edit column. 

Add Button Column in DataGridView

Image
Do the following steps . Step 1: Click on the dataGridView. You will see an arrow sign on the upper right corner. Click on it. Step 2: Select Add Column option. Step 3: Set the Name. Here Name is the button's property name. It is not the display text of button. Set the Type as DataGridViewButtonColumn . Set the Header text. It shows the column's head name. Then press Add and close it. Step 4:  Now a button column has been added to the dataGridView. But the text of the button has not set yet. So click on the arrow sign again and select Edit Columns. Step 5: On the left side, select the column header you want to edit. We select Edit column to change it's properties. Then set the Text and make UseColumnTextForButton true . Then press OK. Step 6: Build and Start your Project. In my database, student table has 3 rows, that's why 3 Update button has been added to dataGridView's Edit column. To do the button column click event, see  this