高手现身,帮小弟一个问题!:)谢谢!(今天好像没有高人在,我发了好几次都没人回贴)

chriskidd 2005-05-19 10:06:56
我的更新内容包括:Id,Code,Name,Type,Publisher,PurDate,Comment。为什么我的更新不能实现:要不就是没改,要不就是为空。。请专家帮我诊断!谢谢!我的毕业设计其他全部完成了,就差这个更新功能了,急人啊!!拜托各位大侠了,小弟拜谢!

程序如下:

Private Sub dgbook_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgbook.UpdateCommand
Dim ds As DataSet = bookInfo.GetBookInfo
Dim Id As Integer
Dim Code As String
Dim Name As String
Dim Type As String
Dim Publisher As String
Dim PurDate As String
Dim Comment As String
'execute the update
Try
Id = CType(e.Item.Cells(0).Text, Integer)
Code = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Name = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Type = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Publisher = CType(e.Item.Cells(4).Controls(0), TextBox).Text
PurDate = CType(e.Item.Cells(5).Controls(0), TextBox).Text
Comment = CType(e.Item.Cells(6).Controls(0), TextBox).Text
updBookInfo.chgbook(Id, Code, Name, Type, Publisher, PurDate, Comment)
Catch ex As SqlException
lbl1.Text = "Sql exception:" & ex.Message
Catch ex As Exception
lbl1.Text = "General exception:" & ex.Message
Finally
dgbook.EditItemIndex = -1
BindGrid(ds)
End Try
End Sub
...全文
200 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
chriskidd 2005-05-19
  • 打赏
  • 举报
回复
我在WEB上点击编辑,然后可以在各个属性框中,修改内容(被选中编辑的一项),之后我就点击更新按钮,可是:
Id = CType(e.Item.Cells(0).Text, Integer)
Code = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Name = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Type = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Publisher = CType(e.Item.Cells(4).Controls(0), TextBox).Text
PurDate = CType(e.Item.Cells(5).Controls(0), TextBox).Text
Comment = CType(e.Item.Cells(6).Controls(0), TextBox).Text
并不能取到我修改的值,,,这个是为什么呢?
贝贝壳壳 2005-05-19
  • 打赏
  • 举报
回复
楼上已经说了。
chriskidd 2005-05-19
  • 打赏
  • 举报
回复
系统这么报错怎么解决啊???谢谢,,拜托!!如下:

General exception:SqlParameterCollection 仅接受非空的 SqlParameter 类型对象,不接受 Int32 对象
fengfangfang 2005-05-19
  • 打赏
  • 举报
回复
myCommand.Parameters.Add(id)
改为
myCommand.Parameters.Add(paraid)
fengfangfang 2005-05-19
  • 打赏
  • 举报
回复
现在还是无法确定程序出现问题的位置
在代码窗口中,找到
updBookInfo.chgbook(Id, Code, Name, Type, Publisher, PurDate, Comment)
按F9,添加一个断点,执行WEB程序,看一下Id,Code等变量是否有值。
按同样的办法看一下程序是否执行到myCommand.ExecuteNonQuery()

chriskidd 2005-05-19
  • 打赏
  • 举报
回复
哦。。对比起,,我理解错了。我有那个函数的,,请看看:
Public Function chgbook(ByVal id As Integer, _
ByVal code As String, _
ByVal name As String, _
ByVal type As String, _
ByVal publisher As String, _
ByVal Purchase As String, _
ByVal Comment As String)

Dim myCommand As SqlCommand
Dim paraid As SqlParameter
Dim paraName As SqlParameter
Dim paraCode As SqlParameter
Dim paraType As SqlParameter
Dim paraPublisher As SqlParameter
Dim paraPurchase As SqlParameter
Dim paraComment As SqlParameter

myCommand = New SqlCommand("ChangeBookInfo", conn)
myCommand.CommandType = CommandType.StoredProcedure

paraid = New SqlParameter("@BookId", SqlDbType.Int, 9)
paraCode = New SqlParameter("@BookCode", SqlDbType.Char, 10)
paraName = New SqlParameter("@BookName", SqlDbType.VarChar, 500)
paraType = New SqlParameter("@BookType", SqlDbType.Char, 10)
paraPublisher = New SqlParameter("@BookPublisher", SqlDbType.VarChar, 500)
paraPurchase = New SqlParameter("@BookPurchaseTime", SqlDbType.Char, 10)
paraComment = New SqlParameter("@BookComment", SqlDbType.VarChar, 500)

paraid.Value = id
paraCode.Value = code
paraName.Value = name
paraType.Value = type
paraPublisher.Value = publisher
paraPurchase.Value = Purchase
paraComment.Value = Comment

myCommand.Parameters.Add(id)
myCommand.Parameters.Add(paraCode)
myCommand.Parameters.Add(paraName)
myCommand.Parameters.Add(paraType)
myCommand.Parameters.Add(paraPublisher)
myCommand.Parameters.Add(paraPurchase)
myCommand.Parameters.Add(paraComment)

If conn.ConnectionString = "" Or conn Is Nothing Then
getConnection()
End If
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
End Function
chriskidd 2005-05-19
  • 打赏
  • 举报
回复
我只有这一个函数,,我的原理是先取值,再修改,,没有单独的修改函数,,我就用下面的程序修改:Id = CType(e.Item.Cells(0).Text, Integer)
Code = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Name = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Type = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Publisher = CType(e.Item.Cells(4).Controls(0), TextBox).Text
PurDate = CType(e.Item.Cells(5).Controls(0), TextBox).Text
Comment = CType(e.Item.Cells(6).Controls(0), TextBox).Text

这样不可以么? 如果加一个修改函数该怎么写啊/?小弟我不会啊!
chriskidd 2005-05-19
  • 打赏
  • 举报
回复
是更新运行后么? 当然可以取到值,,但是,,取的不是更新修改的值啊,还是原来的值。。。
fengfangfang 2005-05-19
  • 打赏
  • 举报
回复
把updBookInfo.chgbook的代码贴出来看看。
fengfangfang 2005-05-19
  • 打赏
  • 举报
回复
Id = CType(e.Item.Cells(0).Text, Integer)
Code = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Name = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Type = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Publisher = CType(e.Item.Cells(4).Controls(0), TextBox).Text
PurDate = CType(e.Item.Cells(5).Controls(0), TextBox).Text
Comment = CType(e.Item.Cells(6).Controls(0), TextBox).Text

能取到值吗
chriskidd 2005-05-19
  • 打赏
  • 举报
回复
运行时,,程序不报错。。。
chriskidd 2005-05-19
  • 打赏
  • 举报
回复
就是值传不进去阿。。。
chriskidd 2005-05-19
  • 打赏
  • 举报
回复
可以取 到原先的值。。。但是,,修改过后,点击更新后,,他们都不做更新!!
baobei7758 2005-05-19
  • 打赏
  • 举报
回复
跟踪下看看数据是否传进去
wlzbaby 2005-05-19
  • 打赏
  • 举报
回复
在 catch{} 里把出错信息打印出来

或者把 try{}catch{} 去掉,看看页面报什么错
贝贝壳壳 2005-05-19
  • 打赏
  • 举报
回复
因为你刚才的贴子删除了。

我怀疑是 显示数据的代码 没有放在 !IsPostBack里
fengfangfang 2005-05-19
  • 打赏
  • 举报
回复
根踪一下Id, Code, Name, Type, Publisher, PurDate, Comment是否取到值了
如果没有值,说明上面的赋值语句有问题
如果取到值了,说明你的updBookInfo.chgbook有问题,可以把updBookInfo.chgbook的代码贴出来看看。
fengfangfang 2005-05-19
  • 打赏
  • 举报
回复
http://www.heimofang.com/bbsxp/ShowPost.asp?id=7267

No3有下载
第8章第8个例子看一下
fengfangfang 2005-05-19
  • 打赏
  • 举报
回复
换一种方式
在DataGrid中把你的EditTemplate中的TextBox,Label都标上Id,然后在UPdate_command中
使用Id = Ctype(CType(e.Item.findcontrol("lblxxx"), Label).Text)
的方法


62,046

社区成员

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

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

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

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