Помогите решить проблему плз Перед вызовом "Fill" не было инициализировано свойство SelectCommand
Код:
..........
.........
.....
//Вызов Экселя//
string Path = System.Windows.Forms.Application.StartupPath + "\\Data\\";
IWorkbook book = NativeExcel.Factory.OpenWorkbook(Path + "VesZNP.xls");
Path = @"\\Docx\report\";
string file_name = Path + DateTime.Now.ToFileTime().ToString() + "VesZNP.xls";
book.SaveAs(file_name);
book = NativeExcel.Factory.OpenWorkbook(file_name);
IWorksheet MySheet = book.ActiveSheet;
IRange range = MySheet.Range[1, 1, 1, 1];
range.Rows.RowHeight = 1;
MySheet.Cells[2, 1].Value = "Расчет " + MyComboData2 + " за период с " + Convert.ToDateTime(MyDateData_c.Date.ToString().Substring(0, 10)) + " по " + Convert.ToDateTime(MyDateData_po.Date.ToString().Substring(0, 10));
int i = 6;
//Подключение к БД "test"//
Connection_manager.Set_Connection("Data Source=test;Initial Catalog=test;Persist Security Info=True;User ID=root; Password = password987564231");
Connection_manager.Set_month("10");
DialogResult = DialogResult.OK;
//подключение SQL - вывожу результат//
SqlConnection MyConnection5 = Connection_manager.GetCurrentConnection();
SqlCommand MySelectCommand5 = new SqlCommand();
MySelectCommand5.CommandText = "CREATE TABLE #PR1 (Job bigint, Suffix smallint, StatusRus nvarchar(100), StartDate datetime, EndDate datetime, BuhOrderCode nvarchar(100), BuhOrderDesc nvarchar(100), ItemID int, SLCode nvarchar(100), FullName nvarchar(500), ItemTypesID int, SN nvarchar(100), ProcessName nvarchar(100), [Route] nvarchar(100), IsTargetItem int, JobOperationID int, QtyReleased numeric(18, 8), QtyComplete numeric(18, 8), ElemNum int, WC int, WorksAspect nvarchar(100), SiteWC nvarchar(100), [Operation] nvarchar(100), Equipment nvarchar(100), EqModelPower nvarchar(100), Payable nvarchar(100), CorrectFactor numeric(18, 8), Profession nvarchar(100), PerformersQty int, [Rank] int, Valuation numeric(18, 8), Laboriousness numeric(18, 8), HasClosedOpers int, Reason nvarchar(100)) insert into #PR1 (Job, Suffix, StatusRus, StartDate, EndDate, BuhOrderCode, BuhOrderDesc, ItemID, SLCode, FullName, ItemTypesID, SN, ProcessName, [Route], JobOperationID, QtyReleased, QtyComplete, ElemNum, WC, WorksAspect, SiteWC, [Operation], Equipment, EqModelPower, Payable, CorrectFactor, Profession, PerformersQty, [Rank], Valuation, Laboriousness, HasClosedOpers, Reason) EXECUTE dbo.GetRptPurpleTrud '2023-04-01', '2023-04-30', 207000, null select SiteWC, buhOrderDesc, sn, sum(#PR1.qtyreleased * #PR1.performersqty * #PR1.Laboriousness) as norma,sum(#PR1.qtyreleased * #PR1.Valuation) as summa from #PR1 group by SiteWC, sn, buhOrderDesc Order by SiteWC, sn, buhOrderDesc";
MySelectCommand5.Parameters.Add("@MyDateParam1", SqlDbType.DateTime);
MySelectCommand5.Parameters["@MyDateParam1"].Value = MyDateData_c.Date;
MySelectCommand5.Parameters.Add("@MyDateParam2", SqlDbType.DateTime);
MySelectCommand5.Parameters["@MyDateParam2"].Value = MyDateData_po.Date;
MySelectCommand5.Connection = MyConnection5;
MySelectCommand5.CommandTimeout = 0;
System.Data.DataTable MyConnteyner18 = new System.Data.DataTable();
SqlDataAdapter MyAdapter18 = new SqlDataAdapter(MySelectCommand5);
MyAdapter18.Fill(MyConnteyner18);
if (MyConnteyner18.Rows.Count > 0)
{
foreach (DataRow MyRow18 in MyConnteyner18.Rows)
{
//MySheet.Cells[i, 1].Value = MyRow18["Description"];i.SlCode + ' (' + i.FullName + ')' as Description
MySheet.Cells[i, 1].Font.Bold = true;
i = i + 0;
// MySheet.Cells[i, 1].Value = "Ф.И.О. Бригадир"; //ЗНП
// MySheet.Cells[i, 2].Value = "Численность (чел.)"; //Суффикс
// MySheet.Cells[i, 3].Value = "Участок по ШР"; //Изделие
//MySheet.Cells[i, 4].Value = "SiteWC"; // Наименование
//MySheet.Cells[i, 5].Value = "buhOrderDesc"; // Кол-во по ЗНП
//MySheet.Cells[i, 6].Value = "norma"; // Выполнено по ЗНП
//MySheet.Cells[i, 7].Value = "sn"; // Вес на 1 изделие
/* MySheet.Cells[i, 8].Value = "ПЛАН Трудоемкость (по знп), н/ч"; // Вес по ЗНП
MySheet.Cells[i, 9].Value = "Пустое поле"; // Е/И
MySheet.Cells[i, 10].Value = "Выработка по бригаде, %";
MySheet.Cells[i, 11].Value = "численность чел.";
MySheet.Cells[i, 12].Value = "ФАКТ Трудоемкость (по знп), н/ч";
MySheet.Cells[i, 13].Value = "Пустое поле";
MySheet.Cells[i, 14].Value = "Выработка по бригаде, %";
MySheet.Cells[i, 15].Value = "численность чел.";*/
range = MySheet.Range[i, 1, i, 15];
range.Borders[XlBordersIndex.xlAround].ColorIndex = XlColorIndex.xlColorIndexAutomatic;
range.Borders[XlBordersIndex.xlInsideAll].ColorIndex = XlColorIndex.xlColorIndexAutomatic;
i++;
SqlConnection MyConnection1 = Connection_manager.GetCurrentConnection();
SqlCommand MySelectCommand1 = new SqlCommand();
//Мой код программы//
//MySelectCommand1.CommandText = "";
MySelectCommand1.Parameters.Add("@MyDateParam1", SqlDbType.DateTime);
MySelectCommand1.Parameters["@MyDateParam1"].Value = MyDateData_c.Date;
MySelectCommand1.Parameters.Add("@MyDateParam2", SqlDbType.DateTime);
MySelectCommand1.Parameters["@MyDateParam2"].Value = MyDateData_po.Date;
MySelectCommand1.Connection = MyConnection1;
MySelectCommand1.CommandTimeout = 0;
System.Data.DataTable MyConnteyner1 = new System.Data.DataTable();
SqlDataAdapter MyAdapter1 = new SqlDataAdapter() ;
MyAdapter1.Fill(MyConnteyner1);
if (MyConnteyner1.Rows.Count > 0)
{
decimal summ = 0;
foreach (DataRow MyRow1 in MyConnteyner1.Rows)
{
MySheet.Cells[i, 4].Value = MyRow1["SiteWC"]; //fullname SiteWC, sn, buhOrderDesc
MySheet.Cells[i, 5].Value = MyRow1["sn"]; //qtyreleased
MySheet.Cells[i, 6].Value = MyRow1["buhOrderDesc"]; //qtycomplete
MySheet.Cells[i, 7].Value = MyRow1["quantity"]; //quantity
MySheet.Cells[i, 8].Value = MyRow1["summa"]; // summa
.......
summ = summ + Convert.ToDecimal(MyRow1["summa"].ToString());
range = MySheet.Range[i, 1, i, 15];
range.Borders[XlBordersIndex.xlAround].ColorIndex = XlColorIndex.xlColorIndexAutomatic;
range.Borders[XlBordersIndex.xlInsideAll].ColorIndex = XlColorIndex.xlColorIndexAutomatic;
i++;
}
}
}
}
book.SaveAs(file_name);
System.Diagnostics.Process.Start(file_name);
Close();
}
}
}
}