Executereader:commandtext属性尚未初始化 [英] Executereader: commandtext property has not been initialized

查看:195
本文介绍了Executereader:commandtext属性尚未初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 ExecuteReader:CommandText属性尚未初始化





我尝试过:



  Dim  cnn1  As  SqlConnection 
Dim cmd1 As SqlCommand
Dim reader1 As SqlDataReader

connetionString = ConfigurationManager.ConnectionStrings( APMCUBIntranetConnectionString)。ConnectionString
cnn1 = SqlConnection(connetionString)
cnn1.Open()
cmd1 = SqlCommand(Sql1,cnn1)

Sql1 = SELECT Count([Questions])作为Tq,SUM(案例时) n [符合性] ='是'然后1否则0结束)如果是,总和([符合] ='否'然后1否则0结束时的情况)作为否,总和([符合性] ='NA'时的情况则为1否则0结束)作为NA,(Count([Questions]) - Sum([Compliance] ='NA'然后1 else 0结束的情况))作为Net FROM [APMCUBIntranet]。[dbo]。[AuditChaptHo]其中Branch = '& DropDownList6.Text& '和Chapter ='CREDIT MANAGEMENT'和SubChap1 ='A.Common Observations'并转换(datetime,AuditStDt,103转换(datetime,'& strDate1& ',103)和转换(datetime) ,'& strDate2& ',103)

reader1 = cmd1.ExecuteReader()
while (reader1.Read())

LblTQ1.Text = reader1 ( 0
LblNA1.Text = reader1( 3
LblNet1.Text = reader1( 4
LblYes1.Text = reader1( 1
LblMks1 .Text = reader1( 1


结束 while
cnn1.Close()
reader1.Close()

解决方案

在定义查询之后,应该初始化你的命令对象 -



 '  cmd1 =新的SqlCommand(Sql1,cnn1) 
Sql1 = SELECT Count([Questions])作为Tq,SUM([Compliance] ='Yes'时的情况,然后是1 else 0 end)如果是,sum([Compliance] ='时的情况否'然后其他0结束)作为否,总和([合规] ='NA'时的情况,然后1其他0结束)作为NA,(计数([问题]) - 总和([合规] ='NA'时的情况)然后1其他0结束))作为Net FROM [APMCUBIntranet]。[dbo]。[AuditChaptHo]其中Branch ='& DropDownList6.Text& '和Chapter ='CREDIT MANAGEMENT'和SubChap1 ='A.Common Observations'并转换(datetime,AuditStDt,103转换(datetime,'& strDate1& ',103)和转换(datetime) ,'& strDate2& ',103)
cmd1 = SqlCommand(Sql1,cnn1)





希望,它有助于:)


ExecuteReader: CommandText property has not been initialized



What I have tried:

Dim cnn1 As SqlConnection
        Dim cmd1 As SqlCommand
        Dim reader1 As SqlDataReader

        connetionString = ConfigurationManager.ConnectionStrings("APMCUBIntranetConnectionString").ConnectionString
        cnn1 = New SqlConnection(connetionString)
        cnn1.Open()
        cmd1 = New SqlCommand(Sql1, cnn1)

        Sql1 = "SELECT Count([Questions]) As Tq, SUM(case when [Compliance]= 'Yes       ' then 1 else 0 end) As Yes, sum(case when [Compliance]= 'No        ' then 1 else 0 end) As No,Sum(case when [Compliance]= 'NA        ' then 1 else 0 end) As NA, (Count  ([Questions]) - Sum(case when [Compliance]= 'NA        ' then 1 else 0 end)) As Net FROM [APMCUBIntranet].[dbo].[AuditChaptHo]  where Branch = '" & DropDownList6.Text & "' and Chapter ='CREDIT MANAGEMENT' and SubChap1 ='A.Common Observations'  and  convert(datetime,AuditStDt,103) between convert(datetime, '" & strDate1 & "',103) and convert(datetime,'" & strDate2 & "',103) "
        
        reader1 = cmd1.ExecuteReader()
        While (reader1.Read())

            LblTQ1.Text = reader1(0)
            LblNA1.Text = reader1(3)
            LblNet1.Text = reader1(4)
            LblYes1.Text = reader1(1)
            LblMks1.Text = reader1(1)


        End While
        cnn1.Close()
        reader1.Close()

解决方案

Your command object should be initialized after you define the query like -

'cmd1 = New SqlCommand(Sql1, cnn1)
Sql1 = "SELECT Count([Questions]) As Tq, SUM(case when [Compliance]= 'Yes ' then 1 else 0 end) As Yes, sum(case when [Compliance]= 'No ' then 1 else 0 end) As No,Sum(case when [Compliance]= 'NA ' then 1 else 0 end) As NA, (Count ([Questions]) - Sum(case when [Compliance]= 'NA ' then 1 else 0 end)) As Net FROM [APMCUBIntranet].[dbo].[AuditChaptHo] where Branch = '" & DropDownList6.Text & "' and Chapter ='CREDIT MANAGEMENT' and SubChap1 ='A.Common Observations' and convert(datetime,AuditStDt,103) between convert(datetime, '" & strDate1 & "',103) and convert(datetime,'" & strDate2 & "',103) "
cmd1 = New SqlCommand(Sql1, cnn1)



Hope, it helps :)


这篇关于Executereader:commandtext属性尚未初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆