Results 1 to 10 of 10

Thread: Try This...

  1. #1

    Thread Starter
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    Try This...

    'create a dataadapater and connectionobject
    Public Function x()
    dim x1 as oledbcommand
    'statements to execute the command object here
    'don't dispose or close
    end function
    public function y()
    dim x1 as oledbcommand
    'statements to execute the command object here
    'don't dispose or close
    end function

    'execute both function simulteniously what will happen?

  2. #2
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Try This...

    Object reference not set to an instance of an object.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Try This...

    What are you asking? Whether there might be concurrency issues occur with the database?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    Re: Try This...

    Private Sub MainFormLoad(sender As System.Object, e As System.EventArgs)

    mycon.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;Data source=dbchat.mdb;persist security info=false"
    mycon.Open()

    End Sub

    Private Function x()
    Dim x1 As New System.Data.OleDb.OleDbCommand("select * from Members",mycon)
    x1.ExecuteNonQuery()
    End Function

    Private Function y()
    Dim x1 As New System.Data.OleDb.OleDbCommand("select * from Members",mycon)
    x1.ExecuteNonQuery()
    End Function


    Private Sub Button1Click(sender As System.Object, e As System.EventArgs)
    Call x
    Call y

    End Sub
    Try in vs.net

  5. #5
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Try This...

    If you open a connection that is already open then there will be a problem.
    Rule: Close the connection after using and just open it when it is needed.

  6. #6

    Thread Starter
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    Re: Try This...

    its not the connection the oledbcommand name. use it twice and don't dispose in one function just keep on using it.

  7. #7
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Try This...

    Quote Originally Posted by iehjsucker
    Private Sub MainFormLoad(sender As System.Object, e As System.EventArgs)

    mycon.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;Data source=dbchat.mdb;persist security info=false"
    mycon.Open()

    End Sub

    Private Function x()
    Dim x1 As New System.Data.OleDb.OleDbCommand("select * from Members",mycon)
    x1.ExecuteNonQuery()
    End Function

    Private Function y()
    Dim x1 As New System.Data.OleDb.OleDbCommand("select * from Members",mycon)
    x1.ExecuteNonQuery()
    End Function


    Private Sub Button1Click(sender As System.Object, e As System.EventArgs)
    Call x
    Call y

    End Sub
    Try in vs.net

    There is no problem about the code, it is just the connection is simultaenously open which not a good practice.

  8. #8

    Thread Starter
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    Re: Try This...

    did you try it

  9. #9
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Try This...

    Yep, Since your using a variable that declared inside a sub then it is exclusive only in that sub and outside of that sub the variable is not recognized.

    I tried it and no problem occur.

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Try This...

    You still haven't told us exactly what it is you want to know. If you're going to make us guess then why should we care?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width