Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Public Sub rsvrpt()
Dim rpt As New reservationrpt() 'The report you created.
Dim MyCommand As New SqlCommand()
Dim myDA As New SqlDataAdapter()
Dim myDS As New DataSet2() 'The DataSet you created.
Dim cn As New SqlConnection(ConnectString())

Try

MyCommand.Connection = cn
MyCommand.CommandText = "SELECT * FROM maintable where irsno=" + irsn
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
myDA.Fill(myDS, "maintable")

myDA.SelectCommand.CommandText = "Select fullname from usertbl where username='" + Login.txtuser.Text + "'"
myDA.Fill(myDS, "usertbl")

myDS.EnforceConstraints = False
rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt
'rpt.PrintOptions.PrinterName = "EPSON LX-300+ /II"
'rpt.PrintToPrinter(1, False, 0, 0)
Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try

End Sub


Good day sir!, i have this code above which is working on my other form.but when i try to put it on my main form,it always prompt for a database login which is not happening on my second form.what should i do about my code? i already add this code on my app.config
XML
<startup useLegacyV2RuntimeActivationPolicy="true">

    <supportedRuntime version="v4.0"/>

  </startup>

.
Posted
Updated 2-Jun-13 15:44pm
v2
Comments
Chester Costa 2-Jun-13 22:51pm    
i solved my own problem.my problem is,i have two tables in my rpt. so i add another code like this
myDA.SelectCommand.CommandText = "Select * from roomtbl where irsno="+ irsn
myDA.Fill(myDS, "roomtbl")

1 solution

Hi kindly include database logon paramets so every time your code is executed it will be automatically logged in.


Try
 
MyCommand.Connection = cn
MyCommand.CommandText = "SELECT * FROM maintable where irsno=" + irsn
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
myDA.Fill(myDS, "maintable")
 
myDA.SelectCommand.CommandText = "Select fullname from usertbl where username='" + Login.txtuser.Text + "'"
myDA.Fill(myDS, "usertbl")
 
myDS.EnforceConstraints = False

'''''INCLUDE THIS'''''''''''''''''''''''''''''''''''''''''''
rpt.SetDatabaseLogon("database_name", "database_password")

rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt
'rpt.PrintOptions.PrinterName = "EPSON LX-300+ /II"
'rpt.PrintToPrinter(1, False, 0, 0)
Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
 
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