error in code to get data from data gride into crystal report

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hello
I am take code from some fourms
but I have error in line in search form
<pre class="prettyprint 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 WindowsFormsApplication1;

namespace TransactionPro
{
public partial class SearchForm : Form
{

public DataTable ourData;
private DataTable newdt;
private DataRow dr;

public SearchForm()
{
InitializeComponent();
dateTimePicker1.Checked = false;
dateTimePicker2.Checked = false;
}

private void button1_Click(object sender, EventArgs e)
{
if (dateTimePicker1.Checked)
{
ourData = DB.Advsearch(&quot;Transactions&quot;, textBox1.Text, textBox2.Text, dateTimePicker1.Text, dateTimePicker2.Text, textBox3.Text);
dataGridView1.DataSource=ourData;
}
else
ourData = DB.Advsearch2(&quot;Transactions&quot;, textBox1.Text, textBox2.Text, textBox3.Text);
dataGridView1.DataSource = ourData;
}

private void SearchForm_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = DB.search(&quot;Transactions&quot;, &quot;id&quot;, &quot;&quot;, 4);

}

private void label8_Click(object sender, EventArgs e)
{

}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

private void textBox3_TextChanged(object sender, EventArgs e)
{

}

private void textBox2_TextChanged(object sender, EventArgs e)
{

}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

}

private void label5_Click(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{

for (int i = 0; i &lt; dataGridView1.SelectedRows.Count; i&#43;&#43;)
{
string temp = dataGridView1.SelectedRows.ToString();
for(int j=0;j&lt;dataGridView1.Columns.Count;j&#43;&#43;)
{

<span style="text-decoration:underline dr = newdt.NewRow();
dr[j] = dataGridView1.SelectedRows.Cells[j].Value.ToString();
}

newdt.Rows.Add(dr);
}
Form2 sf = new Form2(ourData,dataGridView1 );
sf.Show();

}
}

}
[/code]
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
when I click on  button2 it doesnt load form2

and my crystal report view in from2
<pre class="prettyprint 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 CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace TransactionPro
{



public partial class Form2 : Form
{ DataSet ds = new DataSet();
DataTable ourData1;
DataGridView v1;
private DataTable dt;


public ReportDocument CrystalReports(string creportName, System.Data.DataTable tableName)
{
string P_str_creportPath = System.Windows.Forms.Application.StartupPath.Substring(0, System.Windows.Forms.Application.StartupPath.Substring(0, System.Windows.Forms.Application.StartupPath.LastIndexOf(&quot;\&quot;)).LastIndexOf(&quot;\&quot;));
P_str_creportPath &#43;= @&quot;&quot; &#43; creportName;

ReportDocument doc = new ReportDocument();
//DataSet ds = this.GetDs(sum_sql, tableName);
doc.Load(P_str_creportPath);
doc.SetDataSource(dt);
return doc;

}




public Form2(DataTable ourData, DataGridView v)
{

InitializeComponent();
dt = ourData;
v1 = v;
}

private void crystalReportViewer1_Load(object sender, EventArgs e)
{


}

private void Form2_Load(object sender, EventArgs e)
{
crystalReportViewer1.ReportSource = this.CrystalReports(&quot;CrystalReport1.rpt&quot;, dt);


}
}


}



[/code]
<br/>
<span class="x_x_t-marker

<br/>
<span style="font-size:small <span style="font-size:small <br/>

View the full article
 
Back
Top