Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In vb.net i want to get the values from three tables and set the datasource to crystal so i am using following coding but the error will occured please help me for this problem

VB
Dim sqlda As New SqlDataAdapter("select Projid,PName,Date,TotalAmount,Status from PDetails1 where Ccode = '" & cuscode & "' union select dcode,dname,Regdate,Totamt,status from domain where CTno='" & cuscode & "'  union  select Name,wcode,webhostname,Rdate,totamt,Status from webhost where Ccode='" & cuscode & "' union select code,Description,RenewalDate,Amount,Status from Renewal CCode='" & cuscode & "'", con)
            Dim sqlda As New SqlDataAdapter("select T1.Projid,T1.PName,T1.Date,T1.TotalAmount,T1.Status,T2.Dcode,T2.Dname,T2.Regdate,T2.Totamt,T2.Status,T3.Name,T3.Wcode,T3.webhostname,T3.Rdate,T3.totamt,T3.Status,T4.Code,T4.Description,T4.Renewaldate,T4.Amount,T4.Status from PDetails1 T1,Domain T2,Webhost T3,Renewal T4 where T1.Ccode=T2.CTNo and T2.CTno=T3.CCode and T4.CCode=T1.Ccode and T1.CCode= '" & cuscode & "' and T2.CTno='" & cuscode & "' or T3.Ccode='" & cuscode & "' Or T4.CCode='" & cuscode & "' order by T4.CCode", con)
          Dim ProDset1 As New DataSet
          sqlda.Fill(ProDset1)
          'DataGridView1.DataSource = ProDset1.Tables(0)
          Dim rrview As New reportviewer
          Dim RptProstmt As New cusreport
          RptProstmt.SetDataSource(ProDset1.Tables(0))


Please help me
Thanks in advance
Posted
Updated 1-Jan-12 21:35pm
v2
Comments
Karthik Harve 2-Jan-12 3:32am    
what is the error message..??
AmitGajjar 2-Jan-12 3:36am    
Use StoredProcedure to manage your code easily and you can also prevent SQL injection.

Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

There is a good chance that this will cure your problem at the same time!
 
Share this answer
 
Dear use dataset file to build query result & make your report by that dataset
bcoz crystal report showing too much error on connection with database.
if u r uncomfortable i can send u the code
 
Share this answer
 
The likeliest reason is that the concatenated value contains illegal characters such as '. As suggested always use parameters. See: SqlParameter[^]

Another possibilities are that the number of columns in the different select's combined by UNION do not match or the data types do not match.

Also in your latter query, you have both AND and OR conditions combined. However, you have not used any parenthesis, so the chances are that you're going to get wrong results.
 
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