Hello,

I have a vb.net application that runs on a server. There are five client PC's that are connected to the server and all the data is saved on the server from my vb.net application.

To add a record, two sql runs under Commit transaction. One runs an insert statement while the other updates a record.

However, I have noticed a error. The update statement has lot of other fields which are stored correctly, but sometimes (say one out of 100 record) it doesnt stores the correct value to a numeric field. This field is integer and the data is stored from a text box.

This is creating a lot of trouble in my application. Please help.

can you post your code? also, what isn't storing properly with it?

First of all thanks for visiting my query. I am directly calling the textbox's text property and storing it to sql.

Well i am converting the data through the int(txtbox.text.trim) way, in the sql statement itself.

But if there was any problem with the code, it should not update one statement also. I am not able to diagonise the logic behind the error

Here is the code:

con = connect()If frm.rdosudex.Checked = True Thencmd = New SqlClient.SqlCommand("INSERT INTO issuecard(cencode,csession,ctdate,cttime,caction,camount,cdeposit,cdcharge,crtyp,crreason,cdamage,ucode,ctype) " & _"VALUES('" & encode_data & "','" & frm.txtcsession.Text.Trim & "','" & server_date & "','" & server_time & "','" & temp & "','" & frm.txtactionamount.Text.Trim & "','" & securitydepo & "','" & b & "','" & type & "','" & reason & "','" & damage & "'," & cashcode & ",'" & sudexo & "')", con)ElseIf frm.rdocredit.Checked = True Thencmd = New SqlClient.SqlCommand("INSERT INTO issuecard(cencode,csession,ctdate,cttime,caction,camount,cdeposit,cdcharge,crtyp,crreason,cdamage,ucode,ctype) " & _"VALUES('" & encode_data & "','" & frm.txtcsession.Text.Trim & "','" & server_date & "','" & server_time & "','" & temp & "','" & frm.txtactionamount.Text.Trim & "','" & securitydepo & "','" & b & "','" & type & "','" & reason & "','" & damage & "'," & cashcode & ",'" & credit & "')", con)ElseIf frm.rdocash.Checked = True Thencmd = New SqlClient.SqlCommand("INSERT INTO issuecard(cencode,csession,ctdate,cttime,caction,camount,cdeposit,cdcharge,crtyp,crreason,cdamage,ucode,ctype) " & _"VALUES('" & encode_data & "','" & frm.txtcsession.Text.Trim & "','" & server_date & "','" & server_time & "','" & temp & "','" & frm.txtactionamount.Text.Trim & "','" & securitydepo & "','" & b & "','" & type & "','" & reason & "','" & damage & "'," & cashcode & ",'" & cash & "')", con)End Ifcon.Open()cmd.ExecuteNonQuery()con.Close()con = connect()If frm.rdosudex.Checked = True Thencmd = New SqlClient.SqlCommand("update mastercard set csession=" & Int(frm.txtcsession.Text) & ",ccbalance=" & Int(frm.txtnewbalance.Text) & ",cactive='" & t & "',cldate='" & server_date & "',clock='" & lock & "',cccode=" & counter & ",ctype='" & sudexo & "' where cencode=" & encode_data & "and cccode=" & cashcode & "", con)ElseIf frm.rdocredit.Checked = True Thencmd = New SqlClient.SqlCommand("update mastercard set csession=" & Int(frm.txtcsession.Text) & ",ccbalance=" & Int(frm.txtnewbalance.Text) & ",cactive='" & t & "',cldate='" & server_date & "',clock='" & lock & "',cccode=" & counter & ",ctype='" & credit & "' where cencode=" & encode_data & " and cccode=" & cashcode & "", con)Elsecmd = New SqlClient.SqlCommand("update mastercard set csession=" & Int(frm.txtcsession.Text) & ",ccbalance=" & Int(frm.txtnewbalance.Text) & ",cactive='" & t & "',cldate='" & server_date & "',clock='" & lock & "',cccode=" & counter & ",ctype='" & cash & "' where cencode=" & encode_data & " and cccode=" & cashcode & "", con)End Ifcon.Open()cmd.ExecuteNonQuery()con.Close()

As you can see two sql statement are ran. The first one runs an insert statement, which stores all the data correctly to the respective fields in the sql.

The other one updates the record in master table. The problem arises here.

ccbalance=" & Int(frm.txtnewbalance.Text) & "

ccbalance is the field in sql table and the other one is the textbox. The problem arises, say one after 100-200 records, though the statement is executed properly and all the other data are saved correctly, but either no data is saved in this field or say if it was to save 255 it saves just 5.

The two sql statement runs under commit, if either of them fails, niether of them is executed. No error is displayed in the application.

Thanks in advance.

Use paramatized command better than you did, to debug your code efficiently
and send your code again I may help.

This article has been dead for over six months. Start a new discussion instead.