Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 :

C#
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
Updated 12-Oct-12 10:15am
v3
Comments
[no name] 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
[no name] 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

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900