PDA

View Full Version : Records not saved via StoredProcedure


fireblade
09-27-2007, 10:52 PM
Below is my code created in vb.net to insert customer record using a stored procedure.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
comm.CommandType = CommandType.StoredProcedure
comm.CommandText = "insertCustomer"
comm.Parameters.Clear()
comm.Parameters.Add("@Name", SqlDbType.VarChar, 50).Value = Me.txtName.Text
comm.Parameters.Add("@Desc", SqlDbType.VarChar, 50).Value = Me.txtDesc.Text
comm.Connection = conn
conn.Open()
Dim afRows As Integer = comm.ExecuteNonQuery()
conn.Close()
If (afRows) Then
MessageBox.Show("Records successfully added. affeced rows = " & afRows)
End If
End Sub

I have another function aLso which display the records when i give a CustomerID.
Records are ennterd and successrully added to the database. It aLso shows the relevan record for the CustomerID.

but after stoping and restart the debugging process, the records are not displayed.

I think the changes are not committed to the database & after closing the program it rollbacks. I dont know whether it is correct or wrong.

Can any one give me a good idea that i can understand weLL please?

jleone
09-28-2007, 02:46 PM
I handle things a little differently on the vb side but I can see what you are doing. Would you mind posting the stored procedure so I could see the SQL side of things?

nikkiH
09-28-2007, 03:00 PM
You're not trapping errors. I don't see a try/catch here (and I should).
It would be somewhat unusual for the database to use transactions and rollback without being told to do so. Are you sure it isn't throwing an error that you're not seeing due to app settings or page settings?

jleone
09-28-2007, 03:27 PM
I was going to ask the same thing about exceptions, but I decided not to. It wasn't mentioned so I figured the vb code went through but the SQL wasn't doing something properly. Like I said in my earlier post, I handle things a little differently on the vb side than done here so we'll see what's brought to the table.

fireblade
09-28-2007, 06:01 PM
thanx for ur try..

i found the problem.
i changed the database property(sql server express database file : right click from solution explorer) copy always condition.

it worked fine..

jleone
09-28-2007, 06:25 PM
Good to hear. You may want to consider using error handling code for this type of stuff though. Like nikkiH said, it would be beneficial to use try/catch blocks.