CreateCommand Method (SqlConnection)
Creates and returns a
SqlCommand object associated with the
SqlConnection.
In this sample
SqlCommand object is created. It is automatically associated with
SqlConnection that created it.
|
|---|
public void CreateSqlCommand(string myConnString)
{
SqlConnection sqlConnection = new SqlConnection(myConnString);
SqlCommand sqlCommand = sqlConnection.CreateCommand();
sqlCommand.CommandText = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')";
sqlConnection.Open();
try
{
sqlCommand.ExecuteNonQuery();
}
finally
{
sqlConnection.Close();
}
} |
|
|---|
Public Sub CreateSqlCommand(ByVal myConnString As String)
Dim sqlConnection As New SqlConnection(myConnString)
Dim sqlCommand As SqlCommand = sqlConnection.CreateCommand()
sqlCommand.CommandText = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')"
sqlConnection.Open()
Try
sqlCommand.ExecuteNonQuery()
Finally
sqlConnection.Close()
End Try
End Sub |