SP.NET中 ListView(列表视图)的使用前台绑定。
前端代码
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = @ProductID"
InsertCommand="INSERT INTO [Products] ([ProductName], [CategoryID], [UnitPrice]) VALUES (@ProductName, @CategoryID, @UnitPrice)"
SelectCommand="SELECT [ProductID], [ProductName], [CategoryID], [UnitPrice] FROM [Products]"
UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [CategoryID] = @CategoryID, [UnitPrice] = @UnitPrice WHERE [ProductID] = @ProductID">
<DeleteParameters>
<asp:Parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
</InsertParameters>
</asp:SqlDataSource>
web.config 代码:
<connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data
Source=.Initial Catalog=NorthwindIntegrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Dim link1 As New ADODB.ConnectionDim rs As New ADODB.Recordset
Dim pubdatapath As String
Sub opendatabase(datapath As String)'打开数据库函数
If link1.State = 1 Then '如果以连接过,则关闭,初始化下次事务
link1.Close: list2.ListItems.Clear: list2.ColumnHeaders.Clear: c.Clear: list1.ListItems.Clear
End If
link1.ConnectionString = "Provider=microsoft.jet.oledb.4.0data source=" &datapath
link1.Open
pubdatapath = datapath
Set biaoming = link1.OpenSchema(adSchemaColumns)'创建数据库记录集
tablename = ""
Do Until biaoming.EOF
If biaoming("table_name") <>tablename Then '列出所有表
tablename = biaoming("table_name")
list1.ListItems.Add , , tablename
End If
biaoming.MoveNext
Loop
Set biaoming = Nothing
menu1.Enabled = True
list1_MouseUp 1, 0, 10, 10
End Sub
Private Sub Command1_Click() '打开数据库
d.DialogTitle = "打开一个数据库文件进行浏览"
d.InitDir = App.Path
d.FileName = ""
d.Filter = "Access数据库(mdb后缀,推荐格式)|*.mdb"
d.ShowOpen
If d.FileName = "" Then Exit Sub
opendatabase d.FileName
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)