Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Data
Public Class MainClass
Shared Sub Main()
Dim ConnectionString As String
Dim myconnection As SqlConnection
Dim mytransaction As SqlTransaction
Dim mycommand1 As SqlCommand
Dim myparam As SqlParameter
Dim da As SqlDataAdapter
Dim ds As New DataSet()
Dim args() As String = Environment.GetCommandLineArgs
ConnectionString = "Server=(local)\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=SSPI"
myconnection = New SqlConnection(ConnectionString)
myconnection.Open()
da = New SqlDataAdapter("select * from Employee", myconnection)
da.Fill(ds, "Employee")
myconnection.Close()
ds.Tables(0).Rows(0)("FirstName") = "11"
mycommand1 = New SqlCommand("update Employee set FirstName=@FirstName " & "where ID=@ID ", myconnection)
myparam = New SqlParameter("@ID", SqlDbType.SmallInt)
myparam.SourceColumn = "ID"
myparam.SourceVersion = DataRowVersion.Current
mycommand1.Parameters.Add(myparam)
myparam = New SqlParameter("@FirstName", SqlDbType.Int)
myparam.SourceColumn = "FirstName"
myparam.SourceVersion = DataRowVersion.Current
mycommand1.Parameters.Add(myparam)
myconnection.Open()
mytransaction = myconnection.BeginTransaction()
mycommand1.Transaction = mytransaction
da.UpdateCommand = mycommand1
Try
da.Update(ds, "Employee")
mytransaction.Commit()
Console.WriteLine("Order modified successfully !")
Catch e As Exception
mytransaction.Rollback()
Console.WriteLine(e.Message)
Finally
myconnection.Close()
End Try
End Sub
End Class
|