以下是伪代码:
SqlCeResultSet myResultSet = cmd.ExecuteResultSet(Options...etc);
bool found = myResultSet.Seek();
if found {
//do an Update
myResultSet.Read() //make current
//At this point we have a cursor positioned at a row to be edited
myResultSet.SetString(1, "value for col 1");
myResultSet.SetString(2, "value for col 2");
//... etc...
myResultSet.SetString(100, "value for col 100");
//i want to replace above with: CommonMethodToFillRowData(someRow)
//finally update
myResultSet.Update();
} else {
//do an insert
SqlCeUpdatableRecord myRec = myResultSet.CreateRecord();
//set primaryKey
myRec.SetInt32(0, pkValue);
//At this point we have a cursor positioned at a row to be edited
myRec.SetString(1, "value for col 1");
myRec.SetString(2, "value for col 2");
//... etc...
myRec.SetString(100, "value for col 100");
//i want to replace above with: CommonMethodToFillRowData(someRow)
//finally insert
myResultSet.Insert(myRec);
}
根据上面的内容,如果我有100列要准备,它必须重复两次;我想要的是一些CommonMethodToFillRowData();但是,对于这样的方法,我应该使用什么类型的参数?
CommonMethodToFillRowData(SqlCeResultSet or SqlCeUpdatableRecord ? parmRow) {
parmRow.SetInt32(col1, value1)
parmRow.SetString(col2, value2)
...etc.
parmRow.SetString(100, "value for col 100");
}
Directly quoting from MSDN doco on SqlCeUpdatableRecord Class: --> Represents a row of updatable values from the data source. A SqlCeResultSet object contains one or more UpdatableRecords.
如果是这样的话,为什么一旦我通过Seek()定位光标,我就不能直接访问SqlCeResultSet中的单个UpdatableRecord?
如果可能的话,我可以使用:
CommonMethodToFillRowData(SqlCeUpdatableRecord parmRow) {
//end of story
}