如何使用VB.NET为网站填充数据集 [英] How to fill a dataset using VB.NET for a website
本文介绍了如何使用VB.NET为网站填充数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好!
我尝试填充数据集,以便在gridview中获取数据。
以下代码适用于WindowsApplication但不适用于网站。
你能告诉我哪里错了或缺少什么吗?
谢谢!
Imports System.Data
Imports System.Data.OleDb
部分 类 _Default
继承 System.Web.UI.Page
受保护的 Sub ButtonSearch_Click(发件人 As 对象,e 作为 EventArgs)句柄 ButtonSearch.Click
Dim cnfd As 新 OleDbConnection(ConfigurationManager.ConnectionStrings( FoodmartConnectionString)。ConnectionString)
Dim ssql 作为 字符串 = SELECT [customer_id],[lname],[fname] FROM [Customers] WHERE lname like'& TextBoxCustomer.Text& %'ORDER BY [lname]
Dim cmdcust 作为 新 OleDbCommand(ssql,cnfd)
Dim ds 作为 新 DataSet
Dim da As 新 OleDbDataAdapter(cmdcust)
da.Fill(ds, C )
GridViewCustomer.DataSource = ds.Tables( C)
结束 Sub
结束 类
< b>什么我试过了:
我为WindowsApplication尝试了相同的代码并且它可以工作。
解决方案
分配数据源后,
调用DataBind
GridViewCustomer.DataSource = ds.Tables( C)
GridViewCustomer.DataBind()
Hello everyone!
I try to fill a dataset in order to have datas in a gridview.
The following code works for a WindowsApplication but not for a website.
Can you tell me where i am wrong or what is missing?
Thank you!
Imports System.Data
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub ButtonSearch_Click(sender As Object, e As EventArgs) Handles ButtonSearch.Click
Dim cnfd As New OleDbConnection(ConfigurationManager.ConnectionStrings("FoodmartConnectionString").ConnectionString)
Dim ssql As String = "SELECT [customer_id], [lname], [fname] FROM [Customers] WHERE lname like '" & TextBoxCustomer.Text & "%' ORDER BY [lname]"
Dim cmdcust As New OleDbCommand(ssql, cnfd)
Dim ds As New DataSet
Dim da As New OleDbDataAdapter(cmdcust)
da.Fill(ds, "C")
GridViewCustomer.DataSource = ds.Tables("C")
End Sub
End Class
What I have tried:
I tried the same code for a WindowsApplication and it works.
解决方案
callDataBind
after assigning the datasource
GridViewCustomer.DataSource = ds.Tables("C") GridViewCustomer.DataBind()
这篇关于如何使用VB.NET为网站填充数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文