现在遇到的问题是:用asp.net,读取sql1条数据显示出来修改后写回,但里面除了时间字段能够更新外,其它字段都没有更新,各位高手
请告诉我原因和解决方法,小弟万分感谢!源码如下:
1个是读取数据库1条记录显示出来,另外1个是点击更新写入,结果只更新了时间字段,其它没变,请问哪里错了?
Public Function Loadnews(ByVal newsID As Integer) As Boolean
Dim sqlstr As String = "select * from News_info where ID = '" & newsID & "'"
Dim myreader As SqlDataReader
Dim myCmd As SqlCommand
myConn.Open()
myCmd = New SqlCommand(sqlstr, myConn)
myreader = myCmd.ExecuteReader()
If myreader.Read Then
initDropdownList(myreader)
auth.Text = myreader("N_auth")
title.Text = myreader("N_title")
conte.Text = myreader("N_conte")
End If
myCmd.Dispose()
myreader.Close()
myConn.Close()
sqlstr = ""
End Function
Private Sub change_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles change.Click
Dim sql As String
Dim mycmd As SqlCommand
sql = "update News_info set Dept_name='" + dept.SelectedItem.Value.ToString.Trim + "',N_auth='" +
auth.Text.ToString.Trim + "',N_title='" + title.Text.ToString.Trim + "',N_conte='" + conte.Text.ToString.Trim +
"',N_time='" + Now() + "' where ID = '" & newsID & "'"
myConn.Open()
mycmd = New SqlCommand(sql, myConn)
mycmd.ExecuteNonQuery()
mycmd.Dispose()
myConn.Close()
sql = ""
Response.Write("<script>javascript:alert('修改成功!!!');</script>")
End Sub