I have loaded .csv file into the dataset. The csv file(have afew hundreds lines) format is as follow;
"UCPTlogTime","UCPTpointName","UCPTvalue","UCPTunit"
2010-07-05T11:08:07.390+08:00,"Net/LON/wattnode1/VirtFb/nvoCurrent[0]","0.128767","Amperes"
2010-07-05T11:08:10.720+08:00,"Net/LON/wattnode1/VirtFb/nvoPower[0]","28.90336","Watts"
2010-07-05T11:08:11.680+08:00,"Net/LON/wattnode1/VirtFb/nvoCurrent[0]","0.128767","Amperes"
2010-07-05T11:08:18.830+08:00,"Net/LON/wattnode1/VirtFb/nvoPower[0]","34.48953","Watts"
As u can see, in the UCPTvalue column, two different type of datas are saved. What i want to do is before updating the remote server with all those data, i want to seperate the Amperes data and Watts data in the individual column. Is there any C# code to create the new column in dataset and set it w开发者_开发技巧ith the data from existing column?
I wouldn't use datasets, myself. I'd bulk load it into a temp database table, then update the relevant tables for each UCPT unit type (in other words, do it all in a stored procedure).
[edited for more detail]
Create a new table called tmpUpdate.
SQLBulkCopy the data into it.
Then run a stored proc that does multiple updates using it, eg something like
update liveTable set latestAmps=tempUpdate.UCPTvalue
FROM liveAmpTable JOIN tempUpdate ON liveAmpTable.UCPTpointName=tempUpdate.UCPTpointName
WHERE tempUpdate.UCPTunit='Amperes'
update liveTable set latestWatts=tempUpdate.UCPTvalue
FROM liveWattsTable JOIN tempUpdate ON liveWattsTable.UCPTpointName=tempUpdate.UCPTpointName
WHERE tempUpdate.UCPTunit='Watts'
truncate table tempUpdate --clear temp data
This assumes only one user does the updating at the same time.
精彩评论