CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Threaded View

  1. #1
    Join Date
    Jul 2010
    Location
    Watch Window
    Posts
    87

    Question Openconnection Issue

    Hi Friends,
    i have written code for openconnection.show that if connection is really open it should simple return true.or if connection does not open.then it should return falso.but i am getting following errors.
    The best overloaded method match for 'MakeConnection.Form1.OpenConnection(ref System.Data.OleDb.OleDbConnection)' has some invalid arguments D:\chash\MakeConnection\MakeConnection\Form1.cs
    (2)Argument '1' must be passed with the 'ref' keyword
    (3)No enclosing loop out of which to break or continue
    Code:
     
    [
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data.OleDb ;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace MakeConnection
    {
        public partial class Form1 : Form
         {
    
           OleDbConnection conn = new OleDbConnection();
    
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {   
             if ( ! OpenConnection(conn)== true) 
                    {
                   MessageBox.Show("Connection is Not Open");
                   break;
                      }
    
            }
            private bool OpenConnection(ref OleDbConnection conn)
            {
                try
                {
                    conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Imp\abc.mdb");
                    conn.Open();
                    return true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return false;
                }
            }
    
        }
    }
    Last edited by xtab; July 26th, 2010 at 07:11 AM.

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

Featured