Click here to Skip to main content
15,899,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to print the data after saving but it shows this error " Invalid File Path"

Please check the below mentioned code and solve my problem


VB
Dim insql As String = "INSERT INTO patient (recptno,pname,age,address,date,phone,refby,testcode,testname,amount) VALUES (@number1,@text2,@number3,@text4,@text5,@number6,@text7,@text8,@text9,@number10)"

        cmd = New SqlCommand(insql, sqlconn)


        cmd.Parameters.AddWithValue("@number1", reciepttxt.Text)
        cmd.Parameters.AddWithValue("@text2", nametxt.Text)
        cmd.Parameters.AddWithValue("@number3", agetxt.Text)
        cmd.Parameters.AddWithValue("@text4", addresstxt.Text)
        cmd.Parameters.AddWithValue("@text5", datetxt.Text)
        cmd.Parameters.AddWithValue("@number6", phonetxt.Text)
        cmd.Parameters.AddWithValue("@text7", refbytxt.Text)
        cmd.Parameters.AddWithValue("@text8", testcodetxt.Text)
        cmd.Parameters.AddWithValue("@text9", testnametxt.Text)
        cmd.Parameters.AddWithValue("@number10", amounttxt.Text)

        sqlconn.Open()

        rowsins = cmd.ExecuteNonQuery
        sqlconn.Close()

        MessageBox.Show(rowsins.ToString & " row added")
        Dim rptDoc As New ReportDocument
        Dim ds As New MDataSet
        Dim sqlCon As SqlConnection
        Dim dt As New DataTable
        dt.TableName = "Crystal Report Example"
        sqlCon = New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=blissdata;Integrated Security=True")
        Dim da As New SqlDataAdapter("SELECT recptno,pname,age,address,date,phone,refby,testcode,testname,amount FROM patient", sqlCon)
        da.Fill(dt)
        ds.Tables(0).Merge(dt)
        rptDoc.Load(Server.MapPath("CrystalReport1.rpt"))
        rptDoc.SetDataSource(ds)
        CrystalReportViewer1.ReportSource = rptDoc
Posted
Updated 25-Feb-11 21:06pm
v2

1 solution

Check the file path

Here you go

Invalid report file path[^]

Also look at this nice article too

Automatically Printing Crystal Reports in ASP.NET[^]

EDIT
----------------------------------------
Actually for windows applications you should use Application.StartupPath or something instead of Sever.Mappath

Look at these these links

Crystal Report In VB.NET[^]

VB.NET Crystal Reports Load Dynamically[^]

That's all man.
 
Share this answer
 
v3
Comments
Espen Harlinn 26-Feb-11 10:13am    
Reasonable - my 5
Mudasar Ahmad 1-Mar-11 2:33am    
i use vb not asp please solve the problem
thatraja 1-Mar-11 2:38am    
/*i use vb not asp please solve the problem*/
But you have used Server.MapPath in your code so it's web application, right?
Check the 1st link in my answer. Verify the report files in mentioned path(which you have), that's all.
Actually I gave you 2nd link for reference. It will help you too.
After that, still you have any doubt....let me know I'm here with CP. :-)
Mudasar Ahmad 1-Mar-11 2:44am    
Dear Yoy are right to say but i use this own mind but i did not know how i call crystal report in vb please send the solution
thatraja 1-Mar-11 2:55am    
Check my updated answer dude.

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