开发者

ASP.Net : How to update the database?

I am using visual basic as the coding language.

    conSQL.Open()

    Dim cmd As开发者_JAVA百科 New SqlCommand("update Phd_Student set student_name = '" + studentnameTextBox.Text + "' where student_id = '" + studentidno.Text + "'", conSQL)

    cmd.ExecuteNonQuery()

    conSQL.Close()

This does not change the value of the record. I created a breakpoint at line 2 and found that the value of studentnameTextBox.Text in the query is the old value even though I changed the text of the textbox in the form.

Would appreciate any help.


This code isn't anywhere close to being secure. Validate any input information before you use it in a query and consider using stored procedures as well.

And we'll need more information about the page state when you're trying to do this.

Also, put this code in an exception block and in the Finally block put the SQL close command. If anything blows up you're going to want to make sure that the connection is still closed and Finally takes care of that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜