|
-
Sep 18th, 2003, 02:55 AM
#1
Thread Starter
Lively Member
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.
-
Sep 18th, 2003, 03:43 AM
#2
Lively Member
Hi,
Can you give that part of the code so we can analyse the problem.
-
Sep 18th, 2003, 03:51 AM
#3
Thread Starter
Lively Member
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
-
Sep 18th, 2003, 04:03 AM
#4
Lively Member
the code seem ok.... how about the refresh.... how you refresh the datagrid.
-
Sep 18th, 2003, 04:08 AM
#5
Thread Starter
Lively Member
i using listbox,
listbox.refresh when e form load
-
Sep 18th, 2003, 04:26 AM
#6
Lively Member
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.
-
Sep 18th, 2003, 04:41 AM
#7
Thread Starter
Lively Member
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.
-
Sep 18th, 2003, 05:00 AM
#8
Lively Member
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....
-
Sep 18th, 2003, 05:03 AM
#9
Thread Starter
Lively Member
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.
-
Sep 18th, 2003, 05:15 AM
#10
Lively Member
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....
-
Sep 18th, 2003, 08:32 PM
#11
Thread Starter
Lively Member
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?
-
Sep 19th, 2003, 03:06 AM
#12
Lively Member
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.
-
Sep 21st, 2003, 11:30 PM
#13
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|