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

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 …