私の環境ですこれはデータ型 '時間'である。このフィールドを変数に割り当てようとすると(コードスニペットでtimepanを使用していますが、これは明示的に使用するものですが、datetimeと同じ結果のオブジェクトも試しています)、コンパイラは次のMDAエラーを返します。時刻SQLデータ型の生成無効なバリアント例外
InvalidVariant was detected
Invalid variant was detected during a conversion from an unmanaged VARIANT to a managed object. Passing invalid VARIANTs to the CLR can cause unexpected exceptions, corruption or data loss.
何かお手伝いいただきありがとうございました。次のように
コードは次のとおりです。
private void CreateCScrapeObjects(string ItemsToScrapeStoredProc, int MaxItemsPerRequest, int SendRequestTolerance)
{
object tempobjecttotestnull;
string scrapename;
string scrapeurl;
string scrapetemplate;
string latestflag;
string parameter1;
string parameter2;
string parameter3;
string parameter1replacestring;
string parameter2replacestring;
string parameter3replacestring;
int dataitemsperday;
DateTime lastsuccessfulrequesttime;
DateTime lastscrapeddatadate;
TimeSpan scrapetime;
DateTime startdate;
DateTime startdateforrequestitem;
DateTime enddate;
DateTime enddateforrequestitem;
int latestdateoffset;
string scrapefrequencytype;
int scrapefrequencynumber;
string rescrapefrequencytype;
int rescrapefrequencynumber;
Scrapeobject MyScrape = new Scrapeobject();
List<ADODB.Parameter> oParams = new List<ADODB.Parameter>();
ADODB.Recordset oRst = new ADODB.Recordset();
if (_databasequeue.RunStoredProcedure(ItemsToScrapeStoredProc, , oParams, _connectstring, ref oRst, ADODB.ExecuteOptionEnum.adOptionUnspecified))
{
while (!oRst.EOF)
{
scrapename = (string)oRst.Fields[0].Value;
scrapeurl = (string)oRst.Fields[1].Value;
scrapetemplate = (string)oRst.Fields[2].Value;
latestflag = (string)oRst.Fields[3].Value;
tempobjecttotestnull = oRst.Fields[5].Value;
if (tempobjecttotestnull.Equals(System.DBNull.Value))
{ parameter1 = ""; }
else
{ parameter1 = (string)tempobjecttotestnull; }
tempobjecttotestnull = oRst.Fields[7].Value;
if (tempobjecttotestnull.Equals(System.DBNull.Value))
{ parameter2 = ""; }
else
{ parameter2 = (string)tempobjecttotestnull; }
tempobjecttotestnull = oRst.Fields[9].Value;
if (tempobjecttotestnull.Equals(System.DBNull.Value))
{ parameter3 = ""; }
else
{ parameter3 = (string)tempobjecttotestnull; }
tempobjecttotestnull = oRst.Fields[4].Value;
if (tempobjecttotestnull.Equals(System.DBNull.Value))
{ parameter1replacestring = ""; }
else
{ parameter1replacestring = (string)tempobjecttotestnull; }
tempobjecttotestnull = oRst.Fields[6].Value;
if (tempobjecttotestnull.Equals(System.DBNull.Value))
{ parameter2replacestring = ""; }
else
{ parameter2replacestring = (string)tempobjecttotestnull; }
tempobjecttotestnull = oRst.Fields[8].Value;
if (tempobjecttotestnull.Equals(System.DBNull.Value))
{ parameter3replacestring = ""; }
else
{ parameter3replacestring = (string)tempobjecttotestnull; }
dataitemsperday = (int)oRst.Fields[14].Value;
latestdateoffset = (int)oRst.Fields[15].Value;
scrapefrequencytype = (string)oRst.Fields[10].Value;
scrapefrequencynumber = (int)oRst.Fields[11].Value;
rescrapefrequencytype = (string)oRst.Fields[12].Value;
rescrapefrequencynumber = (int)oRst.Fields[13].Value;
scrapetime = TimeSpan.Parse(Convert.ToString (oRst.Fields[16].Value));
lastsuccessfulrequesttime = Convert.ToDateTime(oRst.Fields[17].Value);
lastscrapeddatadate = Convert.ToDateTime(oRst.Fields[18].Value);
startdate = GetNextScrapeDate(scrapefrequencytype, scrapefrequencynumber, lastscrapeddatadate,scrapetime);
enddate = DateTime.Now.AddDays(latestdateoffset);
startdateforrequestitem = startdate;
enddateforrequestitem = GetScrapeRequestEndDate(scrapefrequencytype,scrapefrequencynumber,lastscrapeddatadate,enddate,MaxNGCDataItemsPerRequest,scrapetime);
while(startdateforrequestitem<enddate)
{
if (MyScrape == null)
{
MyScrape = new ScrapeObject();
MyScrape .DefineScrape(startdateforrequestitem, enddateforrequestitem, scrapeurl, scrapetemplate);
MyScrape .AddItemToRequest(latestflag, parameter1, parameter2, parameter3, parameter1replacestring, parameter2replacestring, parameter3replacestring);
}
else
{
int expecteddataitems = ScrapeFrequency.ExpectedDataItems(scrapefrequencytype,scrapefrequencynumber,startdateforrequestitem,enddateforrequestitem,scrapetime);
if (expecteddataitems > MyScrape .MinRemainingScrapeItems(MaxItemsPerRequest))
{
_scrapequeue.AddQueueItem(MyScrape);
MyScrape = null;
MyScrape = new ScrapeObject();
MyScrape .DefineScrape(startdateforrequestitem, enddateforrequestitem, scrapeurl, scrapetemplate);
MyScrape .AddItemToRequest(latestflag, parameter1, parameter2, parameter3, parameter1replacestring, parameter2replacestring, parameter3replacestring);
}
else
{
MyScrape .AddItemToRequest(latestflag, parameter1, parameter2, parameter3, parameter1replacestring, parameter2replacestring, parameter3replacestring);
}
}
}
}
if (MyScrape != null)
{
_scrapequeue.AddQueueItem(MyScrape);
}
}
else
{
//raise error
}
}