更新Detailsview时更新命令错误 [英] Update Command Error when Updating Detailsview
问题描述
伙计们
我有一种情况,但似乎没有办法解决.我想使用UpdateCommand更新DetailsView,但是我在后面的代码中使用它,因为我有某些条件和值需要更新,这就是为什么我不能在标记中做到这一点.我在Page_Init中创建我的数据源.这是我的更新子:
Hi Guys
I have a situation and I don''t seem to get a way around it. I want to update my DetailsView using UpdateCommand but I am using it in my code behind because I have certain conditions and values to be updated and thats why I can''t do it in markup. I create my DataSource at Page_Init. This is my Update Sub:
Private Sub sbUpdateCommand(ByVal sdcmd As String)
Dim Sqlds As New SqlDataSource
Dim strConn As String = ConfigurationManager.ConnectionStrings("PHAKAMA_COMMERCEConnectionString").ConnectionString
Dim conn As New SqlConnection(strConn)
Dim cmd As New SqlCommand(sdcmd, conn)
Try
'conn.Open()
'cmd.ExecuteNonQuery()
'conn.Close()
Sqlds.ConnectionString = "Data Source=PHAKDB;Initial Catalog=" & Session("pstrDB").ToString & ";Persist Security Info=True;User ID=sa;Password=***"
Sqlds.ID = "DataSource1"
Sqlds.UpdateCommand = sdcmd
Sqlds.Update()
Catch ex As Exception
fGenericError(System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name & ":" & System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message)
End Try
End Sub
更新我的详细信息"视图后,出现以下错误:
除非指定了UpdateCommand,否则数据源"DataSource1"不支持更新.
请任何帮助将不胜感激
谢谢,
After I update my Details view I get this follwing error:
Updating is not supported by data source ''DataSource1'' unless UpdateCommand is specified.
Please any help would be appreciated
Thanks,
推荐答案
我找到了解决方案.在ItemUpdating事件中,应添加以下内容以捕获异常:
e.Cancel = True
I found the solution. In ItemUpdating event the following should be added to capture the exception:
e.Cancel = True
这篇关于更新Detailsview时更新命令错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!