问题描述
朋友,
我正在使用Asp.net2005.我在下面发布我的代码.当我执行此代码时,它将无法正常工作(无法正确更新).请调查一下,并帮助我哪里出错了.
导入System.Data
导入System.IO
导入System.Data.SqlClient
局部类changepassword
继承System.Web.UI.Page
Dim con As SqlConnection
昏暗的cmd作为SqlCommand
昏暗的adp作为SqlDataAdapter
Dim ds As DataSet
昏暗的阅读器,如SqlDataReader
< pre lang ="vb">受保护的子Button1_Click(ByVal发送者作为对象,ByVal e作为System.EventArgs)处理Button1.Click</pre>
< pre lang ="vb"> cmd = New SqlCommand(&< b> select * from ureg where uname =``& quot;& amp; TextBox1.Text&& quot; ;''和upass =''&''& amp; TextBox2.Text& amp;''&'',con</b>)
昏暗的阅读器,如SqlDataReader
reader = cmd.ExecuteReader()
如果reader.Read()= True,那么
cmd =新的SqlCommand(& quot; b>更新ureg SET uname =& quot;& amp; TextBox1.Text& amp;" ;, upass =& quot;& amp; TextBox3.文本& quot ;、 cpass =& quot& amp; amp; amp; amp; amp; amp; quot;文本框4" ;&''''&'',con</b>)
cmd.ExecuteNonQuery()
Response.Write(& quot; changed& quot;)
其他
TextBox1.Text =&&"
TextBox2.Text =&&"
TextBox3.Text =&&"
TextBox4.Text =&& quot;
如果结束
reader.Close()
con.Close()</pre>
结束子
< pre lang ="vb">受保护的子Page_Load(ByVal发送者作为对象,ByVal e作为System.EventArgs)处理Me.Load
con =新的SqlConnection(&数据源= gopi;数据库=医院;集成安全性= True")
con.Open()
结束子
结束类</pre>
谢谢和问候,
Gopi A
Hi Friends,
I am using Asp.net 2005. I post my code in below. While i executed this code it will not work (not update properly). Please look into this and help me where i am in wrong.
Imports System.Data
Imports System.IO
Imports System.Data.SqlClient
Partial Class changepassword
Inherits System.Web.UI.Page
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim adp As SqlDataAdapter
Dim ds As DataSet
Dim reader As SqlDataReader
<pre lang="vb">Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click</pre>
<pre lang="vb">cmd = New SqlCommand("<b>select * from ureg where uname = ''" & TextBox1.Text & "'' and upass = ''" & TextBox2.Text & "''", con</b>)
Dim reader As SqlDataReader
reader = cmd.ExecuteReader()
If reader.Read() = True Then
cmd = New SqlCommand("<b>update ureg SET uname = " & TextBox1.Text & ", upass = " & TextBox3.Text & " , cpass = " & TextBox4.Text & " where uname = '' " & TextBox1.Text & " '' ", con</b>)
cmd.ExecuteNonQuery()
Response.Write("changed")
Else
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End If
reader.Close()
con.Close()</pre>
End Sub
<pre lang="vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con = New SqlConnection("Data Source=gopi;database=Hospital;Integrated Security=True")
con.Open()
End Sub
End Class</pre>
Thanks and Regards,
Gopi A
推荐答案
这篇关于使用vb.net代码的asp.net页中的更新命令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!