dadelsen 15 Newbie Poster

litMsg is a "literal", a Server Control from the toolbox/Web Forms Tab.

When you first posted the thread you wrote

"And in Page_Load.."
and "Response.Write"

so I thought your application must be an ASP. NET application, since in a Windows Forms Application the event would be "Form... Load", and there normally is no "Resonse.Write" in a Windows Forms application.

dadelsen 15 Newbie Poster

Sorry, I do not understand what you mean with "Importing some API"

The RT must be able to instantiate a class named "CrystalReport1", else the line Dim objRpt As New CrystalReport1 cannot work.

Normally you would create such a class by adding a crystal report named "CrystalReport1.rpt" into your project. For VS 2003:

  • Rightclick the project in the solution explorer
  • Select "Add New Item"
  • Select "Crystal Report" in the "Add New Item" Dialog, give it the name "CrystalReport1.rpt", finish with "Open".
  • Follow the instructions in the Crystal Report "Wizzard" Gallery.

After this there is a report (=class) CrystalReport1 in your project that can be instantiated.

tuse commented: Thanks +1
iamthwee commented: agreed +14
dadelsen 15 Newbie Poster

Maybe it is because there is no report (=class) "CrystalReport1" in your project.

dadelsen 15 Newbie Poster

In most cases you would use a dataset object to keep a copy of database data inside your program, then insert, change and delete the rows in the dataset and, when done, you would use dataadapters to write the changes from the dataset to the database. But this is too much to be solved in a forum thread. There are books available, for example David Sceppa, Programming ADO.NET.

For directly inserting and deleting data into a database (using a literal on the form to show feedback):

Insert:

Private Sub btnInsertDirect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles btnInsertDirect.Click
        Dim iRet As Integer
        Dim iNextId As Integer
        Dim sConnectionString As String = "server=(local);database=contacts;user=ASPNET"
        Dim conn As New SqlConnection(sConnectionString)
        Dim sSQL As String

        sSQL = "INSERT INTO contacts (contactid, firstname, lastname)" & _
           " VALUES (@contactid, @firstname, @lastname)"

        Dim cmd As New SqlCommand(sSQL, conn)
        iNextId = 123
        cmd.Parameters.Add(New SqlParameter("@contactid", 123))
        cmd.Parameters.Add(New SqlParameter("@firstname", txtFirstName.Text))
        cmd.Parameters.Add(New SqlParameter("@lastname", txtLastName.Text))

        conn.Open()
        Try
            iRet = cmd.ExecuteNonQuery()
            litMsg.Text = String.Format("Inserted {0} records", iRet)
        Catch ex As System.Exception
            litMsg.Text = String.Format("Error: {0}", ex.ToString)
        Finally
            conn.Close()
        End Try

    End Sub

Delete:

Private Sub btnDeleteDirect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteDirect.Click
        Dim iRet As Integer
        Dim sConnectionString As String = "server=(local);database=contacts;user=ASPNET"
        Dim conn As New SqlConnection(sConnectionString)
        Dim sSQL As String

        sSQL = "DELETE FROM contacts WHERE lastname = '" & txtLastName.Text & "'"

        Dim cmd As New SqlCommand(sSQL, conn)
        conn.Open()
        Try
            iRet = cmd.ExecuteNonQuery()
            litMsg.Text = String.Format("Deleted {0} records", iRet)
        Catch ex …
dadelsen 15 Newbie Poster

one problem is the comma before the WHERE.

Replace

& "CS = @NewCS, " _
            & "WHERE fldUser = @OldfldUser " _

by

& "CS = @NewCS  " _
            & "WHERE fldUser = @OldfldUser " _

If more syntax errors please post back

dadelsen 15 Newbie Poster

Think it is an ASP.NET application. I made some changes, marked with XXX. On my system it works. Maybe the changes help you to get your program to work. Databaseprogramming is a wide area.

Imports System
Imports System.data
Imports System.data.sqlclient
'XXX used a standard  dataset since I do not have yours Imports dataset1 
Public Class WebForm1
    Inherits System.Web.UI.Page

'XXX con needs to be in scope when the Insert-Button Click event is handled    
Dim con As SqlConnection 

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'XXX Dim con As SqlConnection 
        Dim cmd As SqlCommand
        Dim adp As SqlDataAdapter 'XXX use SQLDataAdapter Dim adp As sqladapter
        Dim data As DataSet

        'XXX I do not have your database, please change connect string as required. 
        'XXX If you use the SQLClient dataprovider, you do not need the provider keyword.
        'XXX instantiated the con object
        'con.ConnectionString = "Provider=SQLOLEDB;initialcatalog=preethi;database=ACER;integrated security=true"
        con = New SqlConnection
        con.ConnectionString = "database=.;initial catalog=contacts;user=ASPNET;"

        cmd = New SqlCommand  'XXX instantiated the command object 
        'XXX connection is assigned below
        'cmd.Connection = con  
        'XXX cmd=new sqlcommand("select * from emp"),con
        cmd = New SqlCommand("select * from contacts", con) 'XXX

        adp = New SqlDataAdapter(cmd)
        data = New DataSet 'instatiated dataset
        adp.Fill(data)
        
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click

        Dim sSQL As String = "INSERT INTO contacts( contactid, firstname, lastname) VALUES (20, 'User20', 'User20Firstname')"

        Dim cmd As SqlCommand = New SqlCommand(sSQL, con)
        con.Open() 'XXX connection must be opened before command is executed
        cmd.ExecuteNonQuery()
        con.Close() 'XXX …
dadelsen 15 Newbie Poster

The following code replaces the CR+LF that separates the lines in a multiline textbox by a text that will hopefully never be entered by any user.
I tested this with german culture settings.

Dim sLine As String
        sLine = Replace(TextBox1.Text, vbCr & vbLf, ":AxAxA:")
        Dim writer As New StreamWriter("temp.txt", False)
        writer.WriteLine(sLine)
        writer.Close()

        Dim reader As New StreamReader("temp.txt")
        sLine = reader.ReadLine
        reader.Close()
        TextBox2.Text = Replace(sLine, ":AxAxA:", vbCr & vbLf)
dadelsen 15 Newbie Poster

Do you want to
1) step throgh all rows of Table1, and show the row when there is no row with the same path AND filename in Table 2
2) and then do the same vice versa?

If yes, and DBMS is MS SQL Server or Oracle I would use a union:

/* paste this in MS Query Analyzer, use || instead of + for oracle */
DROP TABLE t1
DROP TABLE t2
CREATE TABLE t1(
sPath VARCHAR(20),
sFilename VARCHAR(10)
)
CREATE TABLE t2(
sPath VARCHAR(20),
sFilename VARCHAR(10)
)
INSERT INTO t1 VALUES ( 'P1', 'F1' )
INSERT INTO t1 VALUES ( 'P2', 'F2' )
INSERT INTO t2 VALUES ( 'P1', 'F1' )
INSERT INTO t2 VALUES ( 'P3', 'F3' )

SELECT sPath + sFilename FROM t1 WHERE spath + sfilename NOT IN 
   (SELECT spath + sfilename FROM t2) 
UNION ALL
SELECT sPath + sFilename FROM t2 WHERE spath + sfilename NOT IN 
   (SELECT spath + sfilename FROM t1)


------------------------------ 
P2F2
P3F3
(2 rows affected)