query in updating

srivalli

Well-known member
Joined
May 4, 2005
Messages
189
Programming Experience
Beginner
i wrote the code for storing records to the dbase as follows:


dim da as new sqldataadapter("select * from bankdet",cn)
Try
cn.Open()
str = "insert into bankdet values (' " & TextBox1.Text.Trim & " ','" & TextBox3.Text.Trim & " ',' " & TextBox2.Text & " ') "
str1 = str.ToUpper.Trim(str)
cmd = New SqlCommand(str1, cn)
cmd.ExecuteNonQuery()
MsgBox(" UR RECORD IS SAVED")
Catch ex As SqlClient.SqlException
MessageBox.Show("BANK ALREADY EXISTS ")
Me.TextBox1.Focus()
TextBox1.Text = " "
TextBox3.Text = " "
End Try
cn.Close()
// here textbox2 is autoincrement field.

after saving the data to the backend,
i want to modify the entered data .

what r the changes required.
 
You need to read the data back
Use a select statment instead of an insert statement. Then you can use a datareader to read the data.
 
I think levyuk has misunderstood. Am I correct in assuming that you are inserting a new row and then you want to edit that row? If this is the case, instead of putting the text box values directly into the insert statement, you should put them in a table and use a data adapter to update the database. That way you still have the data in the table after executing the insert statement and you can update as you like. I am inclined to question why you are inserting and then editing though. If you are then going to update the database again, why not just wait until all edits are complete and then insert. If you are not committing the second round of changes to the database then I guess your approach is correct.

Edit:
Also, it would be considered better programming practice to name your fields in an insert statement, like this:

INSERT INTO Table1 (field1, field2) VALUES (value1, value2)

It is not a big deal but I think more correct this way.
 
Last edited:
Back
Top