我很难更改此类以包含具有自动增量的主键字段。这个模式我是通过第三方库从工业设备获取数据,这个方案是自己提供这些库的公司提供的,我们应该为这个数据层添加一个主键字段将需要放置另一层数据访问其他应用程序通过链接的报告检索此数据。
const string connectionString =
"Data Source=(local);Initial Catalog=MyDB;Integrated Security=true";
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
// Create all necessary ADO.NET objects.
var adapter = new SqlDataAdapter("SELECT * FROM MyTable", connection);
var dataSet = new DataSet();
adapter.FillSchema(dataSet, SchemaType.Source, "MyTable");
adapter.InsertCommand = new SqlCommandBuilder(adapter).GetInsertCommand();
DataTable table = dataSet.Tables["MyTable"];
int[] handles = EasyDAClient.DefaultInstance.SubscribeMultipleItems(
new[]
{
new DAItemGroupArguments("", "MyOPCServer.1", "OPCItem01", 1000, null),
new DAItemGroupArguments("", "MyOPCServer.1", "OPCItem02", 1000, null),
new DAItemGroupArguments("", "MyOPCServer.1", "OPCItem03", 1000, null),
new DAItemGroupArguments("", "MyOPCServer.1", "OPCItem04", 1000, null)
},
(_, eventArgs) =>
{
if (eventArgs.Vtq != null)
{
// Fill a DataRow with the OPC data, and add it to a DataTable.
table.Rows.Clear();
DataRow row = table.NewRow();
row["ItemID"] = eventArgs.ItemDescriptor.ItemId;
row["Value"] = eventArgs.Vtq.Value; // The DataRow will make the conversion to a string.
row["Timestamp"] = (eventArgs.Vtq.Timestamp < (DateTime) SqlDateTime.MinValue)
? (DateTime)SqlDateTime.MinValue
: eventArgs.Vtq.Timestamp;
row["Quality"] = (short)eventArgs.Vtq.Quality;
table.Rows.Add(row);
// Update the underlying DataSet using an insert command.
adapter.Update(dataSet, "MyTable");
}
}
);
在当前方案中包含主键字段的任何建议?