加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

[VB.NET]vb.net update 方面问题...

发布时间:2020-12-16 23:36:46 所属栏目:大数据 来源:网络整理
导读: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.TextBox1.Text + ),(psw= + Me.TextBox3.Text + ) where (id= + Me.TextBox
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.TextBox1.Text + ),(psw= + Me.TextBox3.Text + ) where (id= + Me.TextBox1.Text + ) If TextBox2.Text = TextBox3.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 MessageBox.Show( 密码修改成功!,student-system,MessageBoxButtons.OK,MessageBoxIcon.Information) conn.Close() Me.Close() Else System.Windows.Forms.MessageBox.Show( 密码确认失败!,MessageBoxIcon.Information) End If 以上这些就是我的代码.为什么老是更新不了数据库里数据.数据库表名为 yonghu 字段就两个 id psw,窗口为三个输入筐,用户,新密码,确认密码 请高手指点...... __________________________________________________________________________ ding xia __________________________________________________________________________ 你也没执行阿 Cm.ExecuteNonQuery __________________________________________________________________________ 执行了还是更新不了数据 __________________________________________________________________________ Dim strUpdatename As String = update yonghu set (id= + Me.TextBox1.Text + ),(psw= + Me.TextBox3.Text + ) where (id= + Me.TextBox1.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 MessageBox.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 TextBox4.Text <> Then If TextBox4.Text <> TextBox5.Text Then MessageBox.Show( 新密码与重复密码不一致,提示 ) TextBox1.Text = TextBox3.Text = TextBox4.Text = TextBox5.Text = TextBox1.Focus() Return End If sqlcom.CommandText = update psw set 密码= + TextBox4.Text + where 用户名= + TextBox1.Text + and 密码= + TextBox3.Text + End If End If Dim k As Integer = 0 k = sqlcom.ExecuteNonQuery() If k <> 1 Then MessageBox.Show( 用户名不存在或与密码不一致,提示 ) TextBox1.Text = TextBox3.Text = TextBox4.Text = TextBox5.Text = TextBox1.Focus() Return Else MessageBox.Show( 修改成功,提示 ) TextBox1.Text = TextBox3.Text = TextBox4.Text = TextBox5.Text = TextBox1.Focus() Return End If SqlConnection1.Close() Catch ex As Exception MessageBox.Show( 数据出错,提示 ) TextBox1.Text = TextBox3.Text = TextBox4.Text = TextBox5.Text = TextBox1.Focus() Return End Try End Sub __________________________________________________________________________ 楼主的conn没有open,cmd没有执行! 参考楼上,但不要学楼上 __________________________________________________________________________ Cm.Connection = conn if conn.state=Closed then conn.open() Cm.CommandText = strUpdatename Cm.ExecuteNonQuery 这样就好了 __________________________________________________________________________

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读