Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MySQL CrystalReports
Hi,
 
I am making a program (windows application) and i need to conect it to mysql database and make a report but a cant make it to connect the database with crystal report with a dataset any idea??
 
public partial class Form2 : Form { 
private TableLogOnInfo infoEntrada = new TableLogOnInfo(); 
public Form2() { InitializeComponent(); 
} 
private void Form2_Load(object sender, EventArgs e) { confInfoEntrada(); 
CrystalReport1 listaReportes = new CrystalReport1(); 
ReportDocument docReporte = new ReportDocument(); 
MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();
connBuilder.Add("DataBase", "DataBase");
connBuilder.Add("Data Source", "ipwithdatabasemysql");
connBuilder.Add("User Id", "user");
connBuilder.Add("Password", "pwd"); 
MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString); 
docReporte.Load(@"C:\addresstowhere its located\CrystalReport1.rpt"); 
DataTable tablaDatos = new DataTable(); 
try { 
string cadComando = " "; 
cadComando = "SELECT * FROM table"; connection.Open(); 
MySqlDataAdapter adapDatos = new MySqlDataAdapter(cadComando, connection); 
tablaDatos.Clear(); 
adapDatos.Fill(tablaDatos); 
} 
catch (Exception ex) 
{ MessageBox.Show(ex.Message); 
} 
finally { 
connection.Close(); 
} 
listaReportes.Database.Tables[0].SetDataSource(tablaDatos);
crystalReportViewer1.ReportSource = docReporte; crystalReportViewer1.Zoom(1); 
} private void confInfoEntrada() { 
try { 
infoEntrada.ConnectionInfo.ServerName = "ipwithserver"; 
infoEntrada.ConnectionInfo.UserID = "User"; 
infoEntrada.ConnectionInfo.Password = "pwd"; 
infoEntrada.ConnectionInfo.DatabaseName = "database"; 
} catch (Exception ex) { 
MessageBox.Show(ex.Message); 
} 
} 
} 
} 
Posted 20-Nov-12 10:59am
Edited 21-Nov-12 3:22am
Kschuler32.2K
v2
Comments
Kschuler at 20-Nov-12 17:06pm
   
What did you try and what error message did you get?
azteca_04 at 20-Nov-12 17:39pm
   
Hi,
 
i dont get any errors the report just appears blank with no information
joshrduncan2012 at 20-Nov-12 17:26pm
   
Please show code with existing attempt.
azteca_04 at 20-Nov-12 17:38pm
   
<pre>public partial class Form2 : Form
{
private TableLogOnInfo infoEntrada = new TableLogOnInfo();
 
public Form2()
{
InitializeComponent();
}
 
private void Form2_Load(object sender, EventArgs e)
{
confInfoEntrada();
CrystalReport1 listaReportes = new CrystalReport1();
ReportDocument docReporte = new ReportDocument();
MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();
 
connBuilder.Add("DataBase", "DataBase");
connBuilder.Add("Data Source", "ipwithdatabasemysql");
connBuilder.Add("User Id", "user");
connBuilder.Add("Password", "pwd");
 
MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString);

docReporte.Load(@"C:\addresstowhere its located\CrystalReport1.rpt");

DataTable tablaDatos = new DataTable();

try
{
string cadComando = " ";
cadComando = "SELECT * FROM table";
connection.Open();
MySqlDataAdapter adapDatos = new MySqlDataAdapter(cadComando, connection);
tablaDatos.Clear();
adapDatos.Fill(tablaDatos);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
listaReportes.Database.Tables[0].SetDataSource(tablaDatos);
crystalReportViewer1.ReportSource = docReporte;
crystalReportViewer1.Zoom(1);
}
 

private void confInfoEntrada()
{
try
{
infoEntrada.ConnectionInfo.ServerName = "ipwithserver";
infoEntrada.ConnectionInfo.UserID = "User";
infoEntrada.ConnectionInfo.Password = "pwd";
infoEntrada.ConnectionInfo.DatabaseName = "database";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
</pre>
Kschuler at 21-Nov-12 9:23am
   
Next time, please click the Improve Question button and add this code to your original question.
azteca_04 at 21-Nov-12 12:26pm
   
Thks, i have try that option on the link but it does not work, i need to have all the information on the table put ont the report, any more suggestions??
azteca_04 at 21-Nov-12 12:42pm
   
When i try to open the crystalreport to view it. it ask me for the user id and password, which i type and its says it cannot log in (user & password are correct)

1 solution

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

Solution 1

  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid