天天看點

[VB.NET]出錯 ExecuteReader: CommandText 屬性尚未初始化 幫忙看下 線上等!

[VB.NET]出錯 ExecuteReader: CommandText 屬性尚未初始化 幫忙看下 線上等!

出錯 ExecuteReader: CommandText 屬性尚未初始化 幫忙看下 線上等!

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim adapter As SqlDataAdapter

Dim ds As DataSet = New DataSet

Dim myconn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings( "connectionString ").ToString)

Dim aa As String = Request( "l ")

Dim bb As String = Request( "value ")

Dim cc As String = Request( "i_x ")

Dim dd As String = Request( "i_aa ")

Dim constr As String

If aa = Request( "k1 ") Then

constr = "Select * from CompanyContent where companyname like ''% " & bb & "% '' order by companyid desc "

End If

If aa = Request( "k2 ") Then

If cc = "全市搜尋 " Then

constr = "Select * from CompanyContent where companyname like ''% " & bb & "% '' order by companyid desc "

Else

constr = "Select * from CompanyContent where companyname like ''% " & bb & "% ''and companyaddress= '' " + cc + " '' order by companyid desc "

End If

End If

adapter = New SqlDataAdapter(constr, myconn)

adapter.Fill(ds, "Orders ")

Dim pp As New PagedDataSource

pp.DataSource = ds.Tables( "Orders ").DefaultView

pp.AllowPaging = True

pp.PageSize = 20

Dim nPageCount As Integer ''儲存總共的資料頁面數目

Dim a = ds.Tables( "Orders ").Rows.Count ''儲存記錄總數

Dim nPage As Integer ''存放要浏覽目前資料頁面号

If pp.PageCount Mod pp.PageSize > 0 Then

nPageCount = a / pp.PageSize

nPageCount += 1

End If

nPage = Convert.ToInt32(Request.QueryString( "Page "))

If Request.QueryString( "Page ") < 1 Then

nPage = 1

End If

If Request.QueryString( "Page ") > nPageCount Then

nPage = nPageCount

End If

pp.CurrentPageIndex = nPage - 1

lblPageCount.Text = "總共 " & a.ToString() + "條紀錄 "

lblmsg.Text = ( "  " & "頁次: " & nPage.ToString() & "/ " & nPageCount.ToString())

lblmsg.Text += ( "  資料導航: 首 頁 ")

'' If Not pp.IsFirstPage Then

lblmsg.Text += ( " 上一頁 ")

'' End If

'' If Not pp.IsLastPage Then

lblmsg.Text += ( " 下一頁 ")

'' End If

lblmsg.Text += ( " 尾 頁 ")

dstmsg.DataSource = pp

dstmsg.DataBind()

End Sub

好象是定義string的錯把

__________________________________________________________________________

有人能幫忙看下嗎?

__________________________________________________________________________

請參考:

http://www.xproer.com/bbs/revert.aspx?fid=3&tid=615

__________________________________________________________________________

沒看懂

__________________________________________________________________________

看一下是SQL語句,表名、列名是否比對。

__________________________________________________________________________

是2005麼,請把

Dim myconn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings( "connectionString ").ToString)

改為

Dim myconn As SqlConnection = New SqlConnection(ConfigurationManager.AppSettings( "connectionString ").ToString)

__________________________________________________________________________

比對的 我總感覺Dim constr As String 他錯了

__________________________________________________________________________

2003

__________________________________________________________________________

那您看一下運作時constr裡值到底是什麼吧。

__________________________________________________________________________

constr 肯定為空

__________________________________________________________________________