| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 525 人关注过本帖
标题:[求助].net数据库更新问题
只看楼主 加入收藏
fghydx
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-11-5
收藏
 问题点数:0 回复次数:6 
[求助].net数据库更新问题

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Trim(Session("userid")) = "" Or IsDBNull(Session("userid")) Then
Response.Redirect("loin.aspx")
End If

Try
Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection("server=(local);database=lianxi;user id=sa;pwd=")
Dim ad As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("select * from student1 where stuid='" & Trim(Session("userid")) & "'", conn)
Dim st As Data.DataSet = New Data.DataSet
ad.Fill(st, "user")
Label1.Text = st.Tables("user").Rows(0).Item("stuID")
Label2.Text = st.Tables("user").Rows(0).Item("name")
Label3.Text = st.Tables("user").Rows(0).Item("sex")
Label4.Text = st.Tables("user").Rows(0).Item("birthday")
TextBox1.Text = st.Tables("user").Rows(0).Item("adrr")
TextBox2.Text = st.Tables("user").Rows(0).Item("phon")
Catch exc As Exception
Response.Redirect("loin.aspx")
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection("server=(local);database=lianxi;user id=sa;pwd=")
Dim ad As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("update student1 set adrr='" & Trim(textbox1.text)& "' where stuid='" & Trim(Session("userid")) & "'", conn)
Dim st As Data.DataSet = New Data.DataSet

End Sub

我想先把数据库的内容读出来...然后在改了textbox1.text的属性后写回数据库...但是写不回去...

[此贴子已经被作者于2006-11-5 9:41:07编辑过]

搜索更多相关主题的帖子: 数据库 
2006-11-05 09:37
fghydx
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-11-5
收藏
得分:0 

怎么没人回呀....我顶

顶顶顶顶顶 顶顶顶顶顶顶顶顶顶顶顶 顶顶顶顶顶顶顶顶顶顶顶顶顶
顶顶 顶
顶顶 顶


2006-11-05 10:14
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection("server=(local);database=lianxi;user id=sa;pwd=")
Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand ("update student1 set adrr='" & Trim(textbox1.text.Trim())& "' where stuid='" & Trim(Session("userid")) & "'", conn)
cmd.ExecuteNonQuery();
End Sub



飘过~~
2006-11-05 10:32
fghydx
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-11-5
收藏
得分:0 

还是不行呀...那个textbox控件好像就没有接收到输入的文字..还是改不了
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection("server=(local);database=lianxi;user id=sa;pwd=")
Dim ad As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("update student1 set adrr='这样就可以' where stuid='" & Trim(Session("userid")) & "'", conn)
Dim st As Data.DataSet = New Data.DataSet
ad.fill(st,"user")
End Sub
这样直接赋就可以...但带了参就不行了

[此贴子已经被作者于2006-11-5 11:08:11编辑过]


2006-11-05 10:56
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 

带什么参数??


飘过~~
2006-11-05 11:00
fghydx
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-11-5
收藏
得分:0 
("update student1 set adrr='" & Trim(textbox1.text)& "' where stuid='" & Trim(Session("userid")) & "'",conn)
就是这一句的错误,这样写textbox里的内容好像不会随用户的输入改变...还是页面加载时取出来的值.
用textbox的change事件判断textbox的内容改变没有也不行

2006-11-05 11:06
fghydx
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-11-5
收藏
得分:0 

解决啦..但不知道原因.试出来的
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection("server=(local);database=lianxi;user id=sa;pwd=")
Dim ad As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("update student1 set adrr='" & Trim(TextBox1.Text) & "' where stuid='" & Trim(Session("userid")) & "'", conn)
Dim st As Data.DataSet = New Data.DataSet
ad.Fill(st, "user")
End Sub

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
'在此处放置初始化页的用户代码
Session("userid") = 200403010113
Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection("server=(local);database=lianxi;user id=sa;pwd=")
Dim ad As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("select * from student1 where stuid='" & Trim(Session("userid")) & "'", conn)
Dim st As Data.DataSet = New Data.DataSet
ad.Fill(st, "user")
TextBox1.Text = st.Tables("user").Rows(0)("adrr")
End Sub
End Class



放page_loade 里面就不行...


2006-11-05 11:57
快速回复:[求助].net数据库更新问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020636 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved