Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai sir,

my code is

C#
protected void Page_Load(object sender, EventArgs e)
       {
           ReportDocument rptDoc = new ReportDocument();
           DataSet2 ds = new DataSet2(); // .xsd file name
           DataTable dt = new DataTable();

           // Just set the name of data table
           dt.TableName = "Crystal Report Example";
           dt = getAllOrders(); //This function is located below this function
           ds.Tables[0].Merge(dt);

           // Your .rpt file path will be below
           rptDoc.Load(Server.MapPath("../Trial/CrystalReports3.rpt"));

           //set dataset to the report viewer.
           rptDoc.SetDataSource(ds);
           CrystalReportViewer1.ReportSource = rptDoc;
       }
       public DataTable getAllOrders()
       {
           //Connection string replace 'databaseservername' with your db server name

           SqlCommand cmd = new SqlCommand();
           DataSet ds = null;
           SqlDataAdapter adapter;
           try
           {
               conn1.Open();
               //Stored procedure calling. It is already in sample db.
               cmd.CommandText = "getAllOrders";
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Connection = conn1;
               ds = new DataSet();
               adapter = new SqlDataAdapter(cmd);
               adapter.Fill(ds, "Users");
           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message);
           }
           finally
           {
               cmd.Dispose();
               if (conn1.State != ConnectionState.Closed)
                   conn1.Close();
           }
           return ds.Tables[0];
       }


when i execute this code ,i get the error
<target>.A_ID and .A_ID have conflicting properties: DataType property mismatch.

in ds.Tables[0].Merge(dt); this line.

give a solution ,plz help
Posted
Updated 5-Sep-13 19:04pm
v2
Comments
ArunRajendra 6-Sep-13 1:09am    
Looking at the error description it looks like the fields data datatypes are not same. But looking ds.Tables[0] is empty. My guess you might have to define the columns to this Table[0] before doing the merge.
Member 9960222 6-Sep-13 1:23am    
sir, where i can set the datatype?
Member 9960222 6-Sep-13 1:42am    
sir plz reply to my question,where i can set tte datatype ?
thanks in advance
ArunRajendra 6-Sep-13 4:05am    
Try like this and all your columns.
ds.Tables[0].Columns.Add("Dosage", typeof(int));
ds.Tables[0]..Columns.Add("Drug", typeof(string));
Member 9960222 6-Sep-13 5:33am    
thank you sir

Looking at the error description it looks like the fields data datatypes are not same. But looking ds.Tables[0] is empty. My guess you might have to define the columns to this Table[0] before doing the merge.

C#
Try like this and all your columns.
ds.Tables[0].Columns.Add("Dosage", typeof(int));
ds.Tables[0]..Columns.Add("Drug", typeof(string));
 
Share this answer
 
Try this one, it worked for me...
ds.Tables[0].Merge(dt,True, MissingSchemaAction.Ignore);
 
Share this answer
 
 
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