Results 1 to 13 of 13

Thread: Error in adding new record

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Posts
    68

    Error in adding new record

    Hi, it mi again. Pai seh ah, ask so many things in e forum.
    I now doing e adding of records hor, i can add into the database liao. But hor, when i go search, i cannot retrieve e data which i have added in the beri first place. There is a count in e form, n the count works, it got detect e new record. But the listbox juz wont display e record, it display blank fields.
    How will i be able to see the new record? I got refresh e listbox, but it still not works.

  2. #2
    Lively Member
    Join Date
    Jul 2003
    Location
    Kuala Lumpur (Malaysia)
    Posts
    92

    Smile

    Hi,

    Can you give that part of the code so we can analyse the problem.


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Posts
    68
    Ok, below is my codes...

    Dim cnSQL As SqlConnection
    Dim cmSQL As SqlCommand
    Dim strSQL As String
    Dim intRowsAffected As Integer

    Try
    ' Build Insert statement to insert new product into the products table
    strSQL = "INSERT INTO StaffInfo VALUES ('" + txtSur.Text + " ','" + txtName.Text + "','" + txtNUSNo.Text + "','" + txtStaffNo.Text + "','" + _
    txtDes.Text + "','" + txtDep.Text + "','" + txtExt.Text + "','" + txtEmail.Text + "')"

    cnSQL = New SqlConnection(ConnectionString)
    cnSQL.Open()
    cmSQL = New SqlCommand(strSQL, cnSQL)

    'Execute query
    cmSQL.ExecuteNonQuery()


    ' Close and Clean up objects
    cnSQL.Close()
    cmSQL.Dispose()
    cnSQL.Dispose()

    Catch Exp As SqlException
    MsgBox(Exp.Message, MsgBoxStyle.Critical, "SQL Error")

    Catch Exp As Exception
    MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
    End Try

    MessageBox.Show(Me, "Your record is saved!", "Record Saved", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
    Me.Close()
    End Sub

  4. #4
    Lively Member
    Join Date
    Jul 2003
    Location
    Kuala Lumpur (Malaysia)
    Posts
    92
    the code seem ok.... how about the refresh.... how you refresh the datagrid.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Posts
    68
    i using listbox,

    listbox.refresh when e form load

  6. #6
    Lively Member
    Join Date
    Jul 2003
    Location
    Kuala Lumpur (Malaysia)
    Posts
    92
    if you not using the databinding.... then you have to reload the list by requery again and reload the content to the listbox...

    If you does using the databind then you have to check the connection is still open when you refresh the listbox.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Posts
    68
    For e adding, i not using databinding whereas for e viewing, i using databinding.
    Then wat should i do in order to achieve it? For e view, i got refresh e list when e forms load, but this doesnt help at all.

  8. #8
    Lively Member
    Join Date
    Jul 2003
    Location
    Kuala Lumpur (Malaysia)
    Posts
    92
    since you are not using databind and i assume you are not using data object neither.

    So you have to goto to the form load event and looking the query that get the data from your database....

    .... Then write another function or sub to perform similar function as during the form load event ....

    i hope you get what i mean....

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Posts
    68
    I dun really get it. I got 2 forms, 1 add(not using dat binding) n 1 view(using data binding).
    Then wat should i write in the view form for e form_load?
    Can u pls give mi some examples? I too blur liao.. sorrie abt it.

  10. #10
    Lively Member
    Join Date
    Jul 2003
    Location
    Kuala Lumpur (Malaysia)
    Posts
    92
    yupe, the View form...


    can you ( if possible) give us the form load event code ....

    what i mention just now is at the "View" form.... get the query from there...... by the way did you close the data connection somewhere in the code....

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Posts
    68
    Hi, i didnt do e connection in the form load. As in e view form, i need user to search in order to view the whole list of data in e list box.

    Then i do e connection in e search button when clicked. Then how do i get query fr there?

  12. #12
    Lively Member
    Join Date
    Jul 2003
    Location
    Kuala Lumpur (Malaysia)
    Posts
    92
    Hmmm....

    Very hard to imagine the environment... but try to execute the loading part (not the refresh command) after the add button (i guess you have). Or you can show us the code of the loading part.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Posts
    68
    I done it liao.. Thanks for all e help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width