MyProject.exe 中发生“System.NullReferenceException”类型的未处理异常
附加信息:对象引用未设置为对象的实例。
它说, StringCollection strCol 为空,但table.Script()不为空(它包括记录)。它只执行一次 foreach。当它第二次出现时,它给出了这个例外。这是我的代码:
foreach (var item in Sourceclb.Items)
{
Table table = database.Tables[item.ToString()];
StringCollection strCol = table.Script();//Gives exception here
var script = "";
foreach (var key in strCol)
{
script += key;
}
command.Connection = ttbl;
command.CommandText = "USE "+_hedefDb+" \n EXEC sp_sqlexec '"+scriptdondur(script)+ "'";
command.ExecuteNonQuery();
txtLog.AppendText("*TABLE COPIED* "+item.ToString()+" has been copied. \r\n");
}