奇怪数据库不能更新 VB.NET
代码如下..
Imports System.data
Imports System.data.sqlclient
Imports System.data.oledb
Public Class Editinfo
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox3 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox4 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox6 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox7 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox8 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Label6 As System.Web.UI.WebControls.Label
Protected WithEvents Label7 As System.Web.UI.WebControls.Label
Protected WithEvents Label8 As System.Web.UI.WebControls.Label
Protected WithEvents Label9 As System.Web.UI.WebControls.Label
Protected WithEvents Label10 As System.Web.UI.WebControls.Label
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Dim sql As String
sql = "select * from TableUserInfo where UID= " & Trim(Session( "user "))
Dim connstr As String = "server=TSE-D2B6BF793DD;uid=sa;pwd=;database=Correspondence "
Dim myconn As New SqlConnection(connstr)
Dim da As New SqlDataAdapter(sql, myconn)
Dim ds As New DataSet
da.Fill(ds, "TableUserInfo ")
TextBox1.Text = ds.Tables( "TableUserInfo ").Rows(0)( "Name ")
TextBox2.Text = ds.Tables( "TableUserInfo ").Rows(0)( "email ")
TextBox3.Text = ds.Tables( "TableUserInfo ").Rows(0)( "Mobile ")
TextBox4.Text = ds.Tables( "TableUserInfo ").Rows(0)( "UID ")
TextBox6.Text = ds.Tables( "TableUserInfo ").Rows(0)( "Address ")
DropDownList1.SelectedItem.Text = ds.Tables( "TableUserInfo ").Rows(0)( "Gender ")
TextBox7.Text = ds.Tables( "TableUserInfo ").Rows(0)( "Postcode ")
TextBox8.Text = ds.Tables( "TableUserInfo ").Rows(0)( "Telephone ")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String
' Dim passstr As String
Dim litem As ListItem
' passstr = Trim(CStr(text2.Text))
' passagin = Trim(CStr(text3.Text))
str = " ' " & TextBox4.Text & " ' "
Dim sql As String
sql = "select * from TableUserInfo where UID= " & Trim(Session( "user "))
Dim connstr As String = "server=TSE-D2B6BF793DD;uid=sa;pwd=;database=Correspondence "
Dim myconn As New SqlConnection(connstr)
Dim da As New SqlDataAdapter(sql, myconn)
Dim ds As New DataSet
da.Fill(ds, "TableUserInfo ")
Dim dacomm As SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder(da)
ds.Tables( "TableUserInfo ").Rows(0)( "Name ") = Trim(TextBox1.Text)
ds.Tables( "TableUserInfo ").Rows(0)( "email ") = Trim(TextBox2.Text)
ds.Tables( "TableUserInfo ").Rows(0)( "Mobile ") = Trim(TextBox3.Text)
ds.Tables( "TableUserInfo ").Rows(0)( "UID ") = Trim(TextBox4.Text)
ds.Tables( "TableUserInfo ").Rows(0)( "Address ") = Trim(TextBox6.Text)
ds.Tables( "TableUserInfo ").Rows(0)( "Gender ") = Trim(DropDownList1.SelectedItem.Text)
ds.Tables( "TableUserInfo ").Rows(0)( "Postcode ") = Trim(TextBox7.Text)
ds.Tables( "TableUserInfo ").Rows(0)( "Telephone ") = Trim(TextBox8.Text)
da.UpdateCommand = dacomm.GetUpdateCommand
da.Update(ds, "TableUserInfo ")
Session( "xstr ") = "用户修改成功 "
Response.Redirect( "welcome.aspx ")
End Sub
End Class
[解决办法]
你把你的代码发我把