课程设计要做一个图书管理系统的,这是我在数据库更新的代码,就是按下按钮之后更新textbox3里的数据,在下面的代码可以成功更新数据库内容 。
1.用这段代码在页面没什么错误,书上是这样写的,但是更新不了数据库,数据库文件没变化。
Dim str1, strConn As String
str1 = "update memberinfo set 密码问题= @mmwt where 账号=@zh"
‘怎么更新不了数据库啊?
strConn = ConfigurationManager.AppSettings("strConn")
Dim conn As New OleDbConnection(strConn)
conn.Open()
Dim cmd1 As New OleDbCommand(str1, conn)
cmd1.Connection = conn
cmd1.Parameters.Add("@zh", OleDbType.Char, 10, "账号")
cmd1.Parameters.Add("@mmwt", OleDbType.Char, 50, "密码问题")
cmd1.Parameters("@zh").Value = Session("memberno").ToString()
cmd1.Parameters("@mmwt").Value = TextBox3.Text
Response.Write("alert('" + cmd1.Parameters("@mmwt").Value + "');")
cmd1.ExecuteNonQuery()
Dim adp1 As New OleDbDataAdapter(cmd1)
Dim ds1 As New DataSet
Dim n As Integer = adp1.Fill(ds1, "memberinfo")
conn.Close()
2我自己测试了下用下面的代码,.可以成功更新数据库的内容
Dim str1, strConn As String
str1 = "update memberinfo set 密码问题='" + TextBox3.Text + "' where 账号=@zh"
strConn = ConfigurationManager.AppSettings("strConn")
Dim conn As New OleDbConnection(strConn)
conn.Open()
Dim cmd1 As New OleDbCommand(str1, conn)
cmd1.Connection = conn
cmd1.Parameters.Add("@zh", OleDbType.Char, 10, "账号")
cmd1.Parameters("@zh").Value = Session("memberno").ToString()
cmd1.ExecuteNonQuery()
Dim adp1 As New OleDbDataAdapter(cmd1)
Dim ds1 As New DataSet
Dim n As Integer = adp1.Fill(ds1, "memberinfo")
conn.Close()
这到底是怎么回事啊?怎么按第一种代码更新成功,我按照课本上写的啊。