Executescalar中的错误 [英] Error in Executescalar

查看:154
本文介绍了Executescalar中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好试着在count和count1中得到这两个查询的结果但是执行标量中的gwtting错误请帮助我....



hello guys trying to get the result of those two queries in count and count1 but gwtting error in execute scalar please help me....

Private Sub Form13_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim count As Integer
        Dim count1 As Integer
        Dim total As Integer
        Dim cmd As New OleDbCommand()
        Dim cmd1 As New OleDbCommand()
        Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\sachin\db1.mdb;Persist Security Info=True;Jet OLEDB:Database Password=admin")
        con.Open()
        cmd.CommandText = "select count(*) from answer where count=1 ;"
        cmd1.CommandText = "select count(*) from  answer where count=0;"


        count = CType(cmd.ExecuteScalar(), Integer)
        count1 = CType(cmd1.ExecuteScalar(), Integer)


        total = count - count1
        Me.Label1.Text = total
        cmd.Connection = con
        cmd.ExecuteNonQuery()
        con.Close()

推荐答案

为了保持网站清洁,ThePhantomUpvoter发布的答案是创建连接并将其与命令关联。对于OP,您不会通过从网络上复制代码而不是阅读明确的错误消息来学习编程。您需要处理文章或书籍并理解您使用的代码,否则您将始终遇到这样的琐碎问题。
For the sake of keeping the site clean, the answer, as posted by ''ThePhantomUpvoter'' is to create and associate a connection to your command. To the OP, you don''t learn programming by copying code off the web and not reading clear error messages. You need to work through articles or books and understand the code you use, or you will always have trivial issues like this.


这篇关于Executescalar中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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