CommandTypeには、コマンド文字列の解釈方法を指定する名前が含まれています。
CommandType.Text
(SQLテキストコマンドの場合) (デフォルト。)
CommandType.StoredProcedure
ストアドプロシージャの名前。
CommandType.TableDirect
テーブル名。
Executeメソッドの1つを呼び出すと、名前付きテーブルのすべての行と列が返されます。
注:TableDirectだけOLE DBの.NET Frameworkデータプロバイダーによってサポートされています。 CommandTypeがTableDirectに設定されている場合、複数のテーブルアクセスはサポートされていません。それが使用されているか
サンプル例:
OleDbConnection myOleDbConnection =new OleDbConnection("provider=sqloledb;server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI");
OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();
myOleDbCommand.CommandType = CommandType.TableDirect;
myOleDbCommand.CommandText = "Employee";
myOleDbConnection.Open();
OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();
for (int count = 1; count <= 2; count++)
{
myOleDbDataReader.Read();
Console.WriteLine("myOleDbDataReader[\" ID\"] = " +
myOleDbDataReader["ID"]);
Console.WriteLine("myOleDbDataReader[\" FirstName\"] = " +
myOleDbDataReader["FirstName"]);
Console.WriteLine("myOleDbDataReader[\" LastName\"] = " +
myOleDbDataReader["LastName"]);
}
myOleDbDataReader.Close();
myOleDbConnection.Close();
挿入/更新
try
{
using (SqlCeCommand command = conn.CreateCommand())
{
command.CommandText = "Holdings";
command.CommandType = CommandType.TableDirect;
using (SqlCeResultSet rs = command.ExecuteResultSet(ResultSetOptions.Updatable | ResultSetOptions.Scrollable))
{
SqlCeUpdatableRecord record = rs.CreateRecord();
foreach (var r in _commitBatch)
{
int index=0;
record.SetValue(index++, r.TryGetValueOrDefault("IdentifierFromImportSource",string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("SecurityID", string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("SecurityName", string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("SecurityType", string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("AllocationAmount", string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("Position", string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("AnnualFeePercent", string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("MarginAmount", string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("Price", string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("MorningstarSecId", string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("MorningstarSecType", string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("UserID", string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("MorningstarPrice", string.Empty));
record.SetValue(index++, string.Empty);
record.SetValue(index++, r.TryGetValueOrDefault("AnnualFeeFrequency", string.Empty));
record.SetValue(index++, r.TryGetValueOrDefault("TrackingMethod", "1"));
rs.Insert(record);
}
}
}
}
catch (Exception e)
{
NotifyError(this, new ImportErrorEventArgs(e.Message + e.StackTrace, ErrorLevel.Application));
}
はTableDirect.if経由で更新/挿入/削除のアクションを実行することは可能ですはい、あなたも投稿することができますそれのコード。 –
私はちょうど私の答えを更新しました.. @ faheemkhan –
ありがとう、私はそれを確認します。 –