Net-informations.com
SiteMap  | About    

Dataadapter InsertCommand - Sql Server

SqlDataAdapter provides the communication between the Dataset and the Data Source with the help of SqlConnection Object . The InsertCommand in SqlDataAdapter Object manages to insert the data in the specified Data Source .

In the following Source Code shows how to insert data in the Data Source using SqlDataAdapter and SqlCommand object. Open a connection to the Data Source with the help of SqlConnection object and create a SqlCommand object with insert SQL statement, and assign the SqlCommand to the SqlDataAdapter's InsertCommand.




Imports System.Data.SqlClient
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connetionString As String
        Dim connection As SqlConnection
        Dim adapter As New SqlDataAdapter
        Dim sql As String
        connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
        connection = New SqlConnection(connetionString)
        sql = "insert into product (Product_id,Product_name,Product_price) values(7,'Product7',700)"
        Try
            connection.Open()
            adapter.InsertCommand = New SqlCommand(sql, connection)
            adapter.InsertCommand.ExecuteNonQuery()
            MsgBox("Row inserted !! ")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.