为什么我的更新不行?

ircfan 2003-10-19 08:34:27
<Script runat="server">


Sub Page_Load(obj as object , e as eventArgs)

If Session("username") ="" then
Response.Redirect("../Login.aspx")
End If
SessionUser.text =""& Session("Username") &""
Dim int As Int32 = Cint(Request.Querystring("id"))
Dim mySqlConnection As SqlConnection=new SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myDs As New DataSet()
Dim mySqlCommand As New SqlDataAdapter("Select * From companyinfo where id="& int,mySqlConnection)
mySqlConnection.open()
mySqlCommand.Fill(myDs,"companyinfo")
mySqlConnection.Close()

txtcompany.text = myDs.Tables("companyinfo").Rows(0)("name")
txtaddress.text = myDs.Tables("companyinfo").Rows(0)("address")
txttel.text = myDs.Tables("companyinfo").Rows(0)("tel")
txtfax.text = myDs.Tables("companyinfo").Rows(0)("fax")
txtemail.text = myDs.Tables("companyinfo").Rows(0)("email")
txthomepage.text = myDs.Tables("companyinfo").Rows(0)("homepage")
txtlinkman.text = myDs.Tables("companyinfo").Rows(0)("linkman")
txtproduct.text = myDs.Tables("companyinfo").Rows(0)("product")
txtkeyword.text = myDs.Tables("companyinfo").Rows(0)("keyword")
txtbrief.text = myDs.Tables("companyinfo").Rows(0)("brief")

End Sub

Sub Btn_Click(Sender as object, e As EventArgs)
Dim int As Int32 = Cint(Request.Querystring("id"))
Dim mySqlConnection As SqlConnection=new SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim StrSql As String = "update companyinfo set name=@name,address=@address,tel=@tel,fax=@fax,email=@email,homepage=@homepage,linkman=@linkman,product=@product,keyword=@keyword,brief=@brief,date=@date where id=" & int &""
Dim mySqlCommand As New SqlCommand(StrSql, mySqlConnection)
mySqlCommand.Parameters.Add("@name",SqlDbType.Varchar).Value = txtcompany.text
mySqlCommand.Parameters.Add("@address",SqlDbType.Varchar).Value = txtaddress.text
mySqlCommand.Parameters.Add("@tel",SqlDbType.Varchar).Value = txttel.text
mySqlCommand.Parameters.Add("@fax",SqlDbType.Varchar).Value =txtfax.text
mySqlCommand.Parameters.Add("@email",SqlDbType.Varchar).Value = txtemail.text
mySqlCommand.Parameters.Add("@homepage",SqlDbType.Varchar).Value = txthomepage.text
mySqlCommand.Parameters.Add("@linkman",SqlDbType.Varchar).Value = txtlinkman.text
mySqlCommand.Parameters.Add("@product",SqlDbType.Varchar).Value = txtproduct.text
mySqlCommand.Parameters.Add("@keyword",SqlDbType.Varchar).Value = txtkeyword.text
mySqlCommand.Parameters.Add("@brief",SqlDbType.Varchar).Value = txtbrief.text
mySqlCommand.Parameters.Add("@date",SqlDbType.Varchar).value = formatdatetime(datetime.now,2)
'Response.write (StrSql)
'Response.End
mySqlConnection.Open()
mySqlCommand.ExecuteNonQuery()
mySqlConnection.Close()

Response.Redirect("companyinfo_defau.aspx")
Response.End
End Sub
</Script>
...全文
54 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ircfan 2003-10-19
  • 打赏
  • 举报
回复
兄弟。。检测了。我把btn_onclick里面的txtcompany.text打印出来。还是原来的数据。并不是我更新过的数据?
这是怎么回事情。错误就在这。
Inyoureyes 2003-10-19
  • 打赏
  • 举报
回复
"update companyinfo set name=@name,address=@address,tel=@tel,fax=@fax,email=@email,homepage=@homepage,linkman=@linkman,product=@product,keyword=@keyword,brief=@brief,date=@date where id=" & int &""
int后面为什么还连个""?可能是没有满足条件的纪录,你检查一下生成的sql语句
ircfan 2003-10-19
  • 打赏
  • 举报
回复
解释一下:Page_load里面先把记录读取出来。
然后Btn_click是更新到数据库。
不知道是那里出问题了,点击提交,什么错误也没有。就是更新不起来,这是什么原因呀?

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧