Reputation: 17
I'm new in making crystal reports and I'm done creating my crystal report but when running my program it asks for my logon information but after I log in, it says that
logon failed
I tried to look in other questions here in the site but I was not able to find an answer. My Visual Studio is 2013 Ultimate and my sql is sql-server 2014 express.
Here's my code:
Imports System.Data.SqlClient
Imports System.Data.Sql
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim show As String = String.Empty
show &= "select * from fruit_stock "
show &= "where date_received=@daterec"
Using conn As New SqlConnection("server=WIN10;database=fruit_storage;user=fruit_admin;password=admin;")
Using cmd As New SqlCommand
With cmd
.Connection = conn
.CommandType = CommandType.Text
.CommandText = show
.Parameters.AddWithValue("@daterec", TextBox1.Text)
End With
Try
conn.Open()
Dim da As New SqlDataAdapter
Dim ds As New DataSet
da.SelectCommand = cmd
da.Fill(ds, "fruit_stock")
Dim report As New CrystalReport1
CrystalReportViewer1.ReportSource = report
CrystalReportViewer1.Refresh()
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using
End Using
End Sub
End Class
Upvotes: 1
Views: 987
Reputation: 1
Just make it like this. Add user and password:
Dim report As New CrystalReport1
report.SetDatabaseLogon("sa", "your password")
CrystalReportViewer1.ReportSource = report
CrystalReportViewer1.Refresh()
Upvotes: 0
Reputation: 3003
Dim report As New CrystalDecisions.CrystalReports.Engine.ReportDocument
report.Load("<physical filename of your report>")
report.SetDataSource(ds.Tables("fruit_stock"))
<your_crystal_report_viewer_in_your_form>.ReportSource = report
if you are using an embedded report
Dim report As New <Name of your embedded crystal report>
report.SetDataSource(ds.Tables("fruit_stock"))
<your_crystal_report_viewer_in_your_form>.ReportSource = report
Upvotes: 1