Click here to Skip to main content
12,634,788 members (31,773 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
I have a problem in this code i want to Transfer the datas from DataGridView To Crystal Report
but have an error can anybody help me ???

this is my code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DB db = new DB();
        DataSet ds;

        private void button1_Click(object sender, EventArgs e)
        {
            ds = db.ExecuteDataset(CommandType.StoredProcedure, "sp_user_list", "T", new SqlParameter[]
            {
                 new SqlParameter("@sex",comboBox1.Text)
            });
            dataGridView1.DataSource = ds.Tables["T"];
            dataGridView1.Columns[0].HeaderText = "کد کاربر";
            dataGridView1.Columns[1].HeaderText = "نام";
            dataGridView1.Columns[2].HeaderText = "نام خانوادگی";
            dataGridView1.Columns[3].HeaderText = "جنسیت";
            dataGridView1.Columns[4].HeaderText = "تلفن";
            dataGridView1.Columns[5].HeaderText = "آدرس";
        }

        private void button2_Click(object sender, EventArgs e)
        {
           crystalReportViewer1.Enabled = true;
           DataTable dt = new DataTable();
           dt = dataGridView1.DataSource as DataTable;
           ds.Tables.Add(dt);

           //error is in this line . it say the invenrep does not exist.
           invenrep.SetDataSource(ds);

           crystalReportViewer1.ReportSource = invenrep;//this line too            
        }
    }
}

how resolve this problem . what format must be define for " invenrep"???
Posted 12-Oct-12 9:40am
Updated 12-Oct-12 11:15am
v3
Comments
Wes Aday 12-Oct-12 14:46pm
   
okay..... what is it that you think "invenrep" is? You have not declared it.
Sergey Alexandrovich Kryukov 12-Oct-12 14:58pm
   
It must mean "invent_repeatedly", or "invention_repetition_number"... :-)
--SA
Wes Aday 12-Oct-12 15:00pm
   
He copied the code from an incomplete answer to someone else from 2 years ago.
Sergey Alexandrovich Kryukov 12-Oct-12 15:11pm
   
Aha! And what kind of punishment is in order, in such cases? Where is the CodeProject "Malleus Maleficarum", I forgot? :-)

(For those who in a tank :-), I refer to 3-rd part of this:
http://en.wikipedia.org/wiki/Malleus_Maleficarum)

--SA

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

it is giving error that invenrep does not exist because you can't declare that in your code.
so please declare invenrepand than try to run your code.
or
i think your code is incomplete.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 13 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100