Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.Data
Public Class Form1
Inherits System.Windows.Forms.Form
Public Shared Sub Main()
Dim MyIdentityValue As Integer
Dim objConnection As New SqlClient.SqlConnection("server=.;database=pubs;trusted_connection=true")
Dim objCommand As New SqlClient.SqlCommand("INSERT INTO jobs (desc, minV, maxV) VALUES('desc', 50, 100)")
objConnection.Open()
objCommand.Connection = objConnection
If objCommand.ExecuteNonQuery > 0 = True Then
Dim objIdentifier As New SqlClient.SqlCommand("Select @@Identity", objConnection)
Try
MyIdentityValue = objIdentifier.ExecuteScalar
Catch
MyIdentityValue = 0
End Try
End If
objConnection.Close()
System.Console.WriteLine(MyIdentityValue)
End Sub
End Class
|