为什么这样写不对。
zymfy 2003-01-14 04:13:24 '-----------连接数据库
Dim reconn As New SqlClient.SqlConnection(strconn)
'---------建立缓冲---------------
Dim rsadapter As New SqlClient.SqlDataAdapter()
'----------建立记录集-------------------
Dim rsset As New DataSet()
'---------建立command
Dim rsczyb As New SqlClient.SqlCommand("select czybh,czyxm,mm from czyb where czybh='" & czybh & "'", reconn)
rsadapter.SelectCommand = rsczyb
rsadapter.Fill(rsset, "czyb")
'------------------------------------------
If Trim(txtjkl.Text) <> rsset.Tables("czyb").Rows(0).Item(2) Then
MsgBox("旧口令错误,请重新输入", 16, "提示")
txtjkl.Focus()
Exit Sub
End If
'--------------------------
If Trim(txtxkl.Text) <> Trim(txtqrkl.Text) Then
MsgBox("两次新密码输入不一至,请重新输入", 48, "提示信息")
txtxkl.Text = ""
txtqrkl.Text = ""
txtxkl.Focus()
Exit Sub
End If
'--------开始保存-------------
'---------建立回滚----------------
reconn.Open()
'----------------------------------------------
Dim mytrans As SqlClient.SqlTransaction = reconn.BeginTransaction()
Dim mycommand As New SqlClient.SqlCommand()
mycommand.Transaction = mytrans
Try
mycommand.CommandText = "update czyb set mm='" & Trim(txtxkl.Text) & "' where czybh='" & czybh & "'"
mycommand.ExecuteNonQuery()
mytrans.Commit()
'-----------------保存结束后--------------------
MsgBox("保存成功", 48, "提示")
Catch err As Exception
mytrans.Rollback()
MsgBox("保存失败!", 48, "提示")
MsgBox(err.ToString)
Console.WriteLine(err.ToString())
Finally
reconn.Close()
End Try
'-----------------------------------------
当运行到 mycommand.ExecuteNonQuery()时提示CONNECTION尚未初始化.
那位能告诉我怎么做。随便看一下我的代码,是不是可以简化。我是第一次用VB。NET写东东。菜的要命.help ! help !