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

前端之家收集整理的这篇文章主要介绍了[VB.NET]vb.net update 方面问题...前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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 这样就好了 __________________________________________________________________________

猜你在找的VB相关文章