none
urgent help~transfer data in datagridview to report viewer. data not showing RRS feed

  • Question

  •   private void tabPage3_Click(object sender, EventArgs e)
            {
                DataTable t = new DataTable();
                t.Columns.Add("StaffId", typeof(Int16));
                t.Columns.Add("StaffName", typeof(string));
                t.Columns.Add("StaffAddress", typeof(string));
                t.Columns.Add("StaffContact", typeof(string));
               // t.Columns.Add("BankNo", typeof(Int16));
                t.Columns.Add("DoB", typeof(DateTime));
                t.Columns.Add("DutyType", typeof(string));



                t.Rows.Add(1, "df", "asdf", "adsf", 233, "dfa", "sdf", "adf");
                t.Rows.Add(2, "df", "asdf", "adsf", 233, "dfa", "sdf", "adf");
                t.Rows.Add(3, "df", "asdf", "adsf", 233, "dfa", "sdf", "adf");
                t.Rows.Add(4, "df", "asdf", "adsf", 233, "dfa", "sdf", "adf");
                t.Rows.Add(5, "df", "asdf", "adsf", 233, "dfa", "sdf", "adf");
                t.Rows.Add(6, "df", "asdf", "adsf", 233, "dfa", "sdf", "adf");
               // t.Rows.Add(7, "df", "asdf", "adsf", 233, "dfa", "sdf", "adf");
                dataGridView3.DataSource = t;

            }

            private void button8_Click(object sender, EventArgs e)
            {
                DataSet ds1 = new DataSet();

                DataTable dt = new DataTable();

                dt.Columns.Add("StaffId", typeof(Int16));
                dt.Columns.Add("StaffName", typeof(string));
                dt.Columns.Add("StaffAddress", typeof(string));
                dt.Columns.Add("StaffContact", typeof(string));
                //dt.Columns.Add("BankNo", typeof(Int16));
                //dt.Columns.Add("DoB", typeof(DateTime));
                dt.Columns.Add("DutyType", typeof(string));


              int staffid = 0;
                string staffname = string.Empty;
                string staffaddress = string.Empty;
                string staffcontact = string.Empty;
                //string bankno = string.Empty;
               // string dob = string.Empty;
                string dutytype = string.Empty;
                //DataRow r;

                for (int i = 0; i < dataGridView3.RowCount; i++)
                {
                    staffid = Convert.ToInt16(dataGridView3.Rows[i].Cells[0].Value);
                    staffname = dataGridView3.Rows[i].Cells[1].Value.ToString();
                    staffaddress = dataGridView3.Rows[i].Cells[2].Value.ToString();
                    staffcontact = dataGridView3.Rows[i].Cells[3].Value.ToString();
                    // bankno = dataGridView3.Rows[i].Cells[4].Value.ToString();
                   // dob = dataGridView3.Rows[i].Cells[5].Value.ToString();
                    dutytype = dataGridView3.Rows[i].Cells[4].Value.ToString();
                    //dt.Rows.Add(staffid,staffname,staffaddress,staffcontact,dutytype);
                   // r = dt.NewRow();

                   // r["StaffId"] = staffid;
                   // r["StaffName"] = staffname;
                   // r["StaffAddress"] = staffaddress;
                   // r["StaffContact"] = staffcontact;
                   // //  r["BankNo"] = bankno;
                   //// r["DoB"] = dob;
                   // r["DutyType"] = dutytype;
                   // dt.Rows.Add(r);
                }
                foreach (DataGridViewRow dgv in dataGridView3.Rows)
                {
                    dt.Rows.Add(dgv.Cells[0].Value, dgv.Cells[1].Value, dgv.Cells[2].Value, dgv.Cells[3].Value, dgv.Cells[4].Value);//, dgv.Cells[5].Value);
                }

               ds1.Tables.Add(dt);
            ds1.ReadXml("Staff.xml");
              //  ds1.WriteXmlSchema("Staff.xml");

               // DataSet dataset = new DataSet();
               // dataset.ReadXml("Staff.xml");
                StaffsBindingSource.DataSource = ds1;
                //ReportViewer d = new ReportViewer();
                //StaffsBindingSource.DataSource = d;

                this.reportViewer3.RefreshReport();


            }

      
    • Moved by Bob Shen Tuesday, June 25, 2013 6:45 AM
    Saturday, June 22, 2013 1:12 AM

All replies

  • and xml file

    <?xml version="1.0" standalone="yes" ?>
    - <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    - <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    - <xs:complexType>
    - <xs:choice minOccurs="0" maxOccurs="unbounded">
    - <xs:element name="Table1">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element name="StaffId" type="xs:short" minOccurs="0" />
      <xs:element name="StaffName" type="xs:string" minOccurs="0" />
      <xs:element name="StaffAddress" type="xs:string" minOccurs="0" />
      <xs:element name="StaffContact" type="xs:string" minOccurs="0" />
      <xs:element name="DutyType" type="xs:string" minOccurs="0" />
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:choice>
      </xs:complexType>
      </xs:element>
      </xs:schema>

    Saturday, June 22, 2013 1:12 AM
  • Hi xiaoxijiandan,

    I would like to redirect you to appropriate forum for better responses. 


    Bob Shen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 25, 2013 6:44 AM