An unhandled exception of type 'System.NullReferenceException' occurred in MyProject.exe
Additional information: Object reference not set to an instance of an object.
It says , StringCollection strCol is null, but table.Script() is not null (it includes the record). It does the foreach only once. When it comes for a second time it gives this exception. Here is my code:
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");
}