Represents an open connection to a server.
The following example creates a
UniCommand and a
UniConnection. The
UniConnection is opened and set as the
Connection property. The example then calls
Devart.Common.DbCommand.ExecuteNonQuery method, and closes the connection. To accomplish this, the
Devart.Common.DbCommand.ExecuteNonQuery is passed a connection string and a query string that is SQL INSERT statement.
public void InsertRow(string myConnectionString)
{
// If the connection string is empty, use default.
if(myConnectionString == "")
{
myConnectionString = "Provider=SQL Server;Data Source=SERVER;Initial Catalog=Northwind;User ID=sa";
}
UniConnection myConn = new UniConnection(myConnectionString);
string myInsertQuery = "INSERT INTO Test.Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')";
UniCommand myCommand = new UniCommand(myInsertQuery);
myCommand.Connection = myConn;
myConn.Open();
try
{
myCommand.ExecuteNonQuery();
}
finally
{
myConn.Close();
}
}
Public Sub InsertRow(myConnectionString As String)
' If the connection string is empty, use default.
If myConnectionString = "" Then
myConnectionString = "Provider=SQL Server;Data Source=SERVER;Initial Catalog=Northwind;User ID=sa"
End If
Dim myConn As New UniConnection(myConnectionString)
Dim myInsertQuery As String = "INSERT INTO Test.Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')"
Dim myCommand As New UniCommand(myInsertQuery)
myCommand.Connection = myConn
myConn.Open()
Try
myCommand.ExecuteNonQuery()
Finally
myConn.Close()
End Try
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2