Create the Database

  • Go to SQL Server Enterprise Manager
  • Expand the Server icon
  • Right Click on to Database and select New Database
  • Give the name for the Database (say Employee). A Database named Employee is created
  • Right click on to the Database created from the resulting menu, click on to New then click on to Table
  • Now design the table, Save the table with a proper name
Adding Records
  • Expand the Database icon
  • Expand the Database icon of your choice (say Employee)
  • Double click on to Table
  • Right click on the Table which you want to open
  • From the resulting pop up Click on to Open Table and then click on to Return all Rows
  • Now Enter the Records and close the Table
  • If there are many tables and you want to create relationship you can do so by using the Diagrams
Adding Buttons
  • Create a New Project
  • In the new form Add BindingSource control
  • Create the DataSet
  • Now add DataGridView control
  • Now select the DataSource for this, create the adapter for the Table from which you want to get the Data
  • Till now we have filled the data grid with the data from the data adapter in the form’s load event. But let us add a button and when the user clicks on to this button grid is filled with the data
  • Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.EDetailTableAdapter.Fill (Me.EmployeeDataSet.EDetail)
    End Sub
  • Similarly user can add records to the Database by using the Data Grid.
  • So to make this happen, add a button again and when user adds a new record and clicks on to this button a new record will be added to the Database. This is actually done using the Update method of the Data adapter
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.EDetailTableAdapter.Update (Me.EmployeeDataSet.EDetail)
End Sub
Using the Different Adapters for different Tables
  • When you are having more than one table then have different adapters for different table but the same dataset is used
  • So now add one Datagrid and for this while defining the Data source select the table of which you want to display the data (say StdInfo) from DataSet
  • Similarly add one more DataGrid and use while defining the Data Source select the table of which you want to display the data (say Marks) from the Dataset
  • You can also add new records by using the Update method of the respective data adapters to update the table

Queries<< Previous


Our aim is to provide information to the knowledge

comments powered by Disqus