Write this code in second Form
label1.Text = Application.OpenForms["FirstForm"].Controls["controlname"].Text;
Write this code in second Form
label1.Text = Application.OpenForms["FirstForm"].Controls["controlname"].Text;
when working with excel work books please use some standard to read data from excel sheet….
1.Create object for Excel Application
2. Create object for Excel Workbooks
3. Create object for ExcelWorkbook
4.Create object for ExcelWorkSheet
when using Excel 2000 component
{
Excel.Application xla = new Excel.Application();
Excel.Workbooks xlwbs = xla.Workbooks;
Excle.Workbook xlwb; Excel.Worksheet xls;
xlwb=xlwbs.Open(“[ExcelFileName]“, 0, false, 5, “”, “”, true, Excel.XlPlatform.xlWindows, “\t”, false, false, 0, true); xls=(Excel.Worksheet)xlwb.Worksheets["ExcleSheetname"];
}
Read necessary data from excel work sheet and after completion of working with
excel then release objects in which manner they are created…
so
{
ReleaseComObject(xls);
xlwb.close(false,null,null);
ReleaseComObject(xlwb);
xlwbs.Close();
ReleaseComObject(xlwbs);
xla.Quit();
ReleaseComObject(xla);
Gc.Collect();
}
private void ReleaseComObject(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
}
catch (Exception ex){ }
finally { o = null;}
}
if you have more data to check in sql server
like Data1,Data2,Data3…….DataN
the query must be like this
select * from [tablename] where [columnname] in(‘Data1′,’Data2′,’Data3′,…….’DataN’);
then write all the data in a single file each value in one row and save it.like
Data1
Data2
Data3
….
….
….
DataN
save this as one file name.
Then run this program and browse File and click ‘Display’ Button.
write this code in second form in which you want to retrieve data from Form1 and assign to required one.
Application.OpenForms["Form1 "].Controls["controlName"].Text