Click here to Skip to main content
15,909,193 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Iam creating one medical application in that application i have four textboxes and one datagridview in form(1) and Crystal report in form(2)

iam passing data from form(1) to form(2) but when i run the application its showing me exception that Input string was not in a correct format.Couldnt store 18 /06 /2016; in Quantity Column. Expected type is Int32. in dt.Rows.Add(msktextdate.Text, txtname.Text, txtdoctorname.Text, txtaddress.Text); this line

Quantity column is in datagridview but still it showing me above error here im paste my all form(1) and form(2) code

What I have tried:

C#
public void createrow()
{
if (dt.Rows.Count <= 0)
{
DataColumn dc1 = new DataColumn("Quantity", typeof(int));
DataColumn dc2 = new DataColumn("Medicine_name", typeof(string));
DataColumn dc3 = new DataColumn("Medicine_cost", typeof(string));
DataColumn dc4 = new DataColumn("Manufacture_Name", typeof(string));
DataColumn dc5 = new DataColumn("Batch_No", typeof(string));
DataColumn dc6 = new DataColumn("Expiry_Date", typeof(DateTime));
DataColumn dc7 = new DataColumn("Rupees", typeof(int));
DataColumn dc8 = new DataColumn("Total", typeof(int));
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
dt.Columns.Add(dc4);
dt.Columns.Add(dc5);
dt.Columns.Add(dc6);
dt.Columns.Add(dc7);
dt.Columns.Add(dc8);
dt.Rows.Add(msktextdate.Text, txtname.Text, txtdoctorname.Text, txtaddress.Text);
dataGridView1.DataSource = dt;
ds.Tables.Add(dt);
}
private void btnadd_Click(object sender, EventArgs e)
{
createrow();
Form2 frm = new Form2();
frm.Show();

} 

public DataSet returndata()
{
return ds;
}
Form2 code :

private void crystalReportViewer1_Load(object sender, EventArgs e)
{
Form2 frm = new Form2();
CrystalReport1 rpt = new CrystalReport1();
Form1 frm1 = new Form1();
DataSet ds = new DataSet();
ds = frm1.returndata();
rpt.SetDataSource(ds.Tables["table1"]);
crystalReportViewer1.ReportSource = rpt;
crystalReportViewer1.Refresh();
}
Posted
Updated 21-Jun-16 11:36am
Comments
Maciej Los 18-Jun-16 17:18pm    
dt.Rows.Add(msktextdate.Text, ... text is text and nothing else! You have to convert text to integer!
CHill60 21-Jun-16 6:48am    
Your first column is "Quantity" of type int, but you are adding text which is actually a date ... the dt.Rows.Add line seems to have nothing to do with the datatable you are trying to populate

1 solution

Please, start here:
Generate a Crystal Reports report without a database[^]
C# Crystal Reports without database[^]
Crystal Report In Windows Application Without Database Connection[^]

As i stated in the comment to the question, you have to convert data from string to proper data type (int, datetime) when you adding data from textbox control into datatable. How to do that? Please, check: How to: Convert a String to a Number (C# Programming Guide)[^]
 
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