“GridView1”上同时定义了 DataSource 和 DataSourceID。请移除一个定义
我是一个初学者,下面这段代码是为了实现查询功能,我用了数据源,不知道为什么冲突了...PartialClassindexInheritsSystem.Web.UI.Pag...
我是一个初学者,下面这段代码是为了实现查询功能,我用了数据源,不知道为什么冲突了...
Partial Class index
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Call binddata() '绑定数据
End If
End Sub
Sub binddata2(ByVal sql As String)
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\1018me\App_Data\1018data.mdb")
Dim cmd As New OleDbCommand(sql, conn)
Dim adp As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
adp.Fill(ds, "客户数据库")
GridView1.DataSource = ds.Tables("客户数据库").DefaultView
GridView1.DataBind()
conn.Close()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sql As String
If TextBox1.Text = "" Then
sql = "select 公司名称,经营品牌,项目名称,经营范围,经营方式,联系人,电话,传真 from 客户数据库"
Else
sql = "select 公司名称,经营品牌,项目名称,经营范围,经营方式,联系人,电话,传真 from 客户数据库 where 公司名称 like '%" & Trim(TextBox1.Text) & "%'"
End If
Call binddata2(sql)
GridView1.Visible = True
'TextBox1.Text = ""
End Sub
Sub binddata()
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\1018me\App_Data\1018data.mdb")
conn.Open()
'Dim sql As String
'sql = "select 公司名称,经营品牌,项目名称,经营范围,经营方式,联系人,电话,传真 from 客户数据库"
'Dim cmd As New OleDbCommand(sql, conn)
'Dim adp As New OleDbDataAdapter(cmd)
'Dim ds As New DataSet
'adp.Fill(ds, "客户数据库")
'GridView1.DataSource = ds.Tables("客户数据库").DefaultView
GridView1.DataBind()
conn.Close()
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex '设置要显示的新页
Call binddata()
End Sub
End Class 展开
Partial Class index
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Call binddata() '绑定数据
End If
End Sub
Sub binddata2(ByVal sql As String)
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\1018me\App_Data\1018data.mdb")
Dim cmd As New OleDbCommand(sql, conn)
Dim adp As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
adp.Fill(ds, "客户数据库")
GridView1.DataSource = ds.Tables("客户数据库").DefaultView
GridView1.DataBind()
conn.Close()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sql As String
If TextBox1.Text = "" Then
sql = "select 公司名称,经营品牌,项目名称,经营范围,经营方式,联系人,电话,传真 from 客户数据库"
Else
sql = "select 公司名称,经营品牌,项目名称,经营范围,经营方式,联系人,电话,传真 from 客户数据库 where 公司名称 like '%" & Trim(TextBox1.Text) & "%'"
End If
Call binddata2(sql)
GridView1.Visible = True
'TextBox1.Text = ""
End Sub
Sub binddata()
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\1018me\App_Data\1018data.mdb")
conn.Open()
'Dim sql As String
'sql = "select 公司名称,经营品牌,项目名称,经营范围,经营方式,联系人,电话,传真 from 客户数据库"
'Dim cmd As New OleDbCommand(sql, conn)
'Dim adp As New OleDbDataAdapter(cmd)
'Dim ds As New DataSet
'adp.Fill(ds, "客户数据库")
'GridView1.DataSource = ds.Tables("客户数据库").DefaultView
GridView1.DataBind()
conn.Close()
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex '设置要显示的新页
Call binddata()
End Sub
End Class 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询