vb.net update 方面问题... Me.conn = New System.Data.
sqlClient.
sqlConnection Dim Cm As New
sqlClient.
sqlCommand Dim strUpdatename As String = update yonghu set (id= + Me.Text
Box1.Text + ),(psw= + Me.Text
Box3.Text + ) where (id= + Me.Text
Box1.Text + ) If Text
Box2.Text = Text
Box3.Text Then Me.conn.ConnectionString = workstation id= EASYSOFT-2CA1DB ;packet size=4096;integrated security=SSPI;initia & _ l catalog=myfirstdb;persist security info=False Cm.Connection = conn Cm.CommandText = strUpdatename Message
Box.Show( 密码
修改成功!,student-system,Message
BoxButtons.OK,Message
BoxIcon.Information) conn.Close() Me.Close() Else System.Windows.Forms.Message
Box.Show( 密码确认失败!,Message
BoxIcon.Information) End If 以上这些就是我的
代码.为什么老是更新不了
数据库里数据.
数据库表名为 yonghu 字段就两个 id psw,窗口为三个输入筐,
用户,新密码,确认密码 请高手指点...... __________________________________________________________________________ ding xia __________________________________________________________________________ 你也没执行阿 Cm.ExecuteNonQuery __________________________________________________________________________ 执行了还是更新不了数据 __________________________________________________________________________ Dim strUpdatename As String = update yonghu set (id= + Me.Text
Box1.Text + ),(psw= + Me.Text
Box3.Text + ) where (id= + Me.Text
Box1.Text + ) 这里
sql语句错了!! 你把“(”括号去掉就可以了。 __________________________________________________________________________ 我的给你看看,
用户名,原密码,新密码,重复密码 Imports System.Data.
sqlClient Public Class Form6 Dim ds As New DataSet() Private Sub Form6_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load
sqlConnection1.ConnectionString = data source=allen;Initial Catalog=Pubs;User ID=sa;password= If
sqlConnection1.State = ConnectionState.Closed Then Try
sqlConnection1.Open() Catch ex As Exception Message
Box.Show(
数据库连接出错,
提示 ) Return End Try End If End Sub Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click If Text
Box4.Text <> Then If Text
Box4.Text <> Text
Box5.Text Then Message
Box.Show( 新密码与重复密码不一致,
提示 ) Text
Box1.Text = Text
Box3.Text = Text
Box4.Text = Text
Box5.Text = Text
Box1.Focus() Return End If
sqlcom.CommandText = update psw set 密码= + Text
Box4.Text + where
用户名= + Text
Box1.Text + and 密码= + Text
Box3.Text + End If End If Dim k As Integer = 0 k =
sqlcom.ExecuteNonQuery() If k <> 1 Then Message
Box.Show(
用户名不存在或与密码不一致,
提示 ) Text
Box1.Text = Text
Box3.Text = Text
Box4.Text = Text
Box5.Text = Text
Box1.Focus() Return Else Message
Box.Show(
修改成功,
提示 ) Text
Box1.Text = Text
Box3.Text = Text
Box4.Text = Text
Box5.Text = Text
Box1.Focus() Return End If
sqlConnection1.Close() Catch ex As Exception Message
Box.Show( 数据出错,
提示 ) Text
Box1.Text = Text
Box3.Text = Text
Box4.Text = Text
Box5.Text = Text
Box1.Focus() Return End Try End Sub __________________________________________________________________________ 楼主的conn没有open,cmd没有执行! 参考楼上,但不要学楼上 __________________________________________________________________________ Cm.Connection = conn if conn.state=Closed then conn.open() Cm.CommandText = strUpdatename Cm.ExecuteNonQuery 这样就好了 __________________________________________________________________________
原文链接:https://www.f2er.com/vb/263380.html