1
我正在運行單元測試,當我試圖在數據庫中插入數據並獲取它後,我什麼也沒有得到(我試過用DataAdapter
和DataReader
)。插入後立即返回行沒有結果
但是,當我插入3秒睡眠(即使1秒鐘不工作...)插入和選擇之間我得到的結果。
在SQL Server Profiler中,我可以看到執行,插入完成並在選擇開始前大約10毫秒完成。
我無法找出這來自
的代碼看起來是這樣的: 插入方法
SqlCommand command = new SqlCommand(sqlTemplate);
command.Parameters.Add(Sql4oConstants.Sql4oIdParameterName, SqlDbType.UniqueIdentifier).Value = id;
command.Parameters.Add(Sql4oConstants.Sql4oTimestampParamterName, SqlDbType.DateTime).Value = DateTime.Now;
command.CommandTimeout = dataSourceDescription.CommandTimeout;
DatabaseManager.ExecuteNonQuery(dataSourceDescription.ConnectionString, command);
Get方法
public static void Fill(string connectionString, DataTable table, SqlCommand command)
{
try
{
LogStorageWriter.WriteLogEntry(log, EStorageLevelLog.Debug, string.Format("Execute query: {0}", command.CommandText));
using (SqlConnection conn = new SqlConnection(connectionString))
{
command.Connection = conn;
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
adapter.Fill(table);
}
}
}
catch (InvalidOperationException e)
{
LogStorageWriter.WriteLogEntry(log, EStorageLevelLog.Error, string.Format("Exception : {0}", e.ToString()));
}
}
向我們顯示您的代碼。 –
您可以將'SELECT ...'附加到sql中的'INSERT'。然後你可以在一個命令中執行這兩個操作 –
請顯示一些代碼 –