一个简单的小错误~! 问题在哪里呢?
出错信息:
当传递具有已修改行的 DataRow 集合时,更新要求有效的 UpdateCommand。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml " >
<%@Import Namespace=System.Data.oledb%>
<%@Import Namespace=System.Data%>
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:DataList ID= "dlA " runat= "server " OnItemCommand= "dlA_ICMD " GridLines= "Horizontal ">
<ItemTemplate>
<ASP:Image ID= "Image1 " ImageUrl= "ico1.gif " Runat= "Server "/>
姓名: <%#Container.DataItem( "UserName ")%>
<ASP:LinkButton Id= "lbShow " Text= "> " Runat= "Server "/>
</ItemTemplate>
<EditItemTemplate>
<ASP:Image ImageUrl= "ico1.gif " Runat= "Server "/>
姓名: <%#Container.DataItem( "UserName ")%> <br/>
电话: <ASP:TextBox Id= "T1 " Text= ' <%#Container.DataItem( "phone ")%> ' Runat= "Server "/> <br/>
住址: <ASP:TextBox Id= "T2 " Text= ' <%#Container.DataItem( "firstName ")%> ' Runat= "Server "/> <br/>
电邮: <ASP:TextBox Id= "T3 " Text= ' <%#Container.DataItem( "lastName ")%> ' Runat= "Server "/> <br/>
<ASP:LinkButton Id= "lbCancel " Text= "[放弃] " Runat= "Server "/>
<ASP:LinkButton Id= "lbSubmit " Text= "[确定] " Runat= "Server "/> <br/>
</EditItemTemplate>
<SelectedItemTemplate>
<ASP:Image ImageUrl= "ico1.gif " Runat= "Server "/>
姓名: <%#Container.DataItem( "UserName ")%>
<ASP:LinkButton Id= "lbClose " Text= " < " Runat= "Server "/> <br/>
电话: <%#Container.DataItem( "phone ")%> <br/>
住址: <%#Container.DataItem( "firstName ")%> <br/>
电邮: <%#Container.DataItem( "lastName ")%> <br/>
<ASP:LinkButton Id= "lbEdit " Text= "[编辑] " Runat= "Server "/> <br/>
</SelectedItemTemplate>
</asp:DataList>
</div>
</form>
<Script Language= "VB " Runat= "Server ">
Dim strConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=D:\IIS\Banking.mdb "
Dim strComStr As String = "Select * From tblUsers "
Dim dscA As OleDbDataAdapter = New OleDbDataAdapter(strComStr, strConStr)
Dim dsDataSet As DataSet = New DataSet
Dim dtDataTable As DataTable
Sub Page_Load(Sender As Object, e As EventArgs)
dscA.Fill(dsDataSet, "tblUsers ")
dtDataTable=dsDataSet.Tables( "tblUsers ")
dlA.DataSource=dtDataTable.DefaultView
If Not Page.IsPostBack Then Page.DataBind()
End Sub
Sub dlA_ICMD(Sender As Object, e As DataListCommandEventArgs)
If e.CommandSource.Id = "lbShow " Then
dlA.SelectedIndex = e.Item.ItemIndex
ElseIf e.CommandSource.Id = "lbClose " Then
dlA.SelectedIndex = -1
ElseIf e.CommandSource.Id = "lbEdit " Then
dlA.EditItemIndex = e.Item.ItemIndex
ElseIf e.CommandSource.Id = "lbCancel " Then
dlA.EditItemIndex = -1
ElseIf e.CommandSource.Id = "lbSubmit " Then
Dim txtTemp As TextBox
txtTemp = e.Item.FindControl( "T1 ") '取回ListItem 中名为T1 的控件参
dtDataTable.Rows(dlA.EditItemIndex)( "phone ") = txtTemp.Text
txtTemp = e.Item.FindControl( "T2 ") '取回ListItem 中名为T2 的控件参
dtDataTable.Rows(dlA.EditItemIndex)( "firstName ") = txtTemp.Text
txtTemp = e.Item.FindControl( "T3 ") '取回ListItem 中名为T3 的控件参
dtDataTable.Rows(dlA.EditItemIndex)( "lastName ") = txtTemp.Text
dscA.Update(dsDataSet, "tblUsers ")
dlA.EditItemIndex = -1
End If
dlA.DataBind()
End Sub
</Script>
</body>
</html>
[解决办法]
Dim dscA As OleDbDataAdapter = New OleDbDataAdapter(strComStr, strConStr)
-----------
晕,才发现是oledb的
OleDbCommandBuilder myCommandBuilder = new OleDbCommandBuilder(dscA);
把这句加到你Dim dscA As OleDbDataAdapter = New OleDbDataAdapter(strComStr, strConStr)
下面就好了
[解决办法]
Data Source=D:\IIS\Banking.mdb
路么不能用绝对路么吧?(把Banking.mdb放到网站应用程序根目录下面)
Dim strConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source= "&Server.MapPath( "Banking.mdb ")