Performing Data Manipulations using Disconnected Model

Performing Data Manipulations using Disconnected Model:

Inserting the record using disconnected model

UntitledOpen SQL SERVER

Create

Take a new WINFORM and design like

 

Screenshot_60

 

// Code for button1_click

Imports System.Data

Imports System.Data.SqlClient

In form

‘Form declarations

Dim cn as SqlConnection

Dim da as SqlDataAdapter

Dim cmb as SqlCommandBuilder

Dim ds as DataSet

 

// Form_Load

Cn = New SqlConnection (“user id = sa; password = 123; database = northwind; data source = sekhar”)

da = New SqlDataAdapter (“Select * from dept270”, cn)

cmb = New SqlCommandBuilder (da)

ds = New DataSet

da.Fill (ds, “dept270”)

ds.Tables (“Dept270”).Constrints.Add (“deptno_Pk”,

ds.tables (“Dept270”).Columns (“dept no”), True)

// Code for Add Department (button_click)

Try

Dim row as DataRow

row = ds.Tables (“Dept270”).NewRow

row (“dept no”) = txt Deptno.Text

row (“dept name”) = txt Dname.Text

row (“Loc”) = txtLoc.Text

ds.Tables (“Dept270”).Rows.Add (row da.update (ds.Tables (“Dept270”))

If MessageBox.Show (“Department added do you want to add another department”, Me.Text, MessageBoxbuttons.YesNo, MessageBoxIcon Question) = Windows.Forms.DIalogResult.Yes Then

txtDeptno.Clear ()

txtDname.Clear ()

txtLoc.Clear ()

txtDeptno.Clear ()

Else

End

End if

Catch ex as Exception

MessageBox.Show (ex.Message, “Error”)

End try

Untitled Execute

Performing updations and deletions using ADD.Net disconnected model

 

 

Screenshot_61

 

Imports System.Data

Imports System.Data.SqlClient

‘Form declarations

Dim cn as SqlConnection

Dim da as SqlDataAdapter

Dim cmb as SqlCommandBuilder

Dim ds as DataSet

Dim row as DataRow

Form_Load

Cn = New SqlConnection (“user id = sa; password = 123; database = northwind; data source = sekhar”)

da = New SqlDataAdapter (“Select * from dept270”, cn)

cmb = New SqlCommandBuilder (da)

ds = New DataSet

da.Fill (ds, “dept270”)

ds.Tables (“Dept270”).Constrints.Add (“deptno_Pk”,

ds.tables (“Dept270”).Columns (“dept no”), True)

// Code for Add Department (button_click)

‘Search (button_click)

Dim dno as Integer

Dno = Val (txtDeptno.Text)

If ds.tables (“dept270”).Rows.Contains (dno) = True

Then

Row = ds.Tables (“dept270”).Rows.Find (dno)

txtDname.Text = row (“Dname”)

txtLoc.Text = row (“Loc”)

Else

MessageBox.Show (“Department not found”, “Error”)

‘Update (button_click)

Try

row (“dname”) = txtDname.Text

row (“loc”) = txtloc.Text

row.EndEdit ()

da.Update (ds.Tables (“dept270”))

MessageBox.Show (“Record updated”, Me.Text)

Catch ex as Exception

MessageBox.Show (ex.Message, “Error”)

End try

// ‘Delete (button_click)

Try

row.Delete ()

da.Update (ds.Tables (“dept270”))

MessageBox.Show (“Record Deleted”, Me.Text)

txtDeptno.Clear ()

txtDname.Clear ()

txtLoc.Clear ()

txtDeptno.Clear ()

Catch ex as Exception

MessageBox.Show (ex.Message, “Error”)

End try

‘Close (button_click)

End

Concepts to remember (Add.Net disconnected model)

  • Projecting the data (all rows & navigations)
  • Various search methods supported
  • Relationships between tables
  • Data manipulations

 

COM Interoperability Model:

Whenever a COM component is used within a .Net application or if a .Net assembly is used from a COM type application then it is said to be supporting COM interoperability.

 

Using COM Components from .Net application

Screenshot_62

 

 

Whenever a .Net application uses the definition of COM component then a request will be given to the CLR where the CLR identifies the request type and defines Runtime Callable Wrapper (RCW)

Once RCW is defined then it sends a request for the COM server where the COM component is identified based on its GUID (Global Unique identifier) and the component type library definitions will be returned to the RCW.

Once RCW collects the data then it creates an interoperable COM which is an assembly once the assembly is created then the .Net application will consume that assembly and provides the output.

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Performing Data Manipulations using Disconnected Model"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Support


    Please leave a message and we'll get back to you soon.
    Three + 6