Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys trying to get the result of those two queries in count and count1 but gwtting error in execute scalar please help me....

VB
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()
Posted
Comments
[no name] 2-Jun-13 6:37am    
Are you going to tell us what error or are we supposed to guess?
sachin bhise 2-Jun-13 6:42am    
m getting the following error
connection property has not been initialized
[no name] 2-Jun-13 6:48am    
That would be because you have not set the command object's connection property, cmd.Connection = con.
sachin bhise 2-Jun-13 7:01am    
where should i put the cmd.Connection = con in the above code?
pls tell me.
sachin bhise 2-Jun-13 7:04am    
thanks a lot....my friend problem solved....thnks...

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900