13

Вопрос по c# – Непоследовательная доступность

Я получаю следующую ошибку

Inconsistent accessibility: parameter type 'Db.Form1.ConnectionString' is less accessible than method 'Db.Form1.BuildConnectionString(Db.Form1.ConnectionString)'

//Name spaces
using System;
using System.Collections.Generic;
using System.ComponentModel;
 using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
 using System.Windows.Forms;
using Microsoft.VisualBasic;
using System.Collections;
using System.Diagnostics;
using System.Data.OleDb;
using System.IO;
using System.Drawing.Printing;

 //
  namespace Db
{
  public partial class Form1 : Form
  {
     public Form1()
     {
        InitializeComponent();
     }
     public void SetBusy()
    {
        this.Cursor = Cursors.WaitCursor;
        Application.DoEvents();
    }
    public void SetFree()
    {
        this.Cursor = Cursors.Default;
        Application.DoEvents();
    }
   //connection string into parts
    struct ConnectionString
    {
        public string Provider;
        public string DataSource;
        public string UserId;
        public string Password;
        public string Database;
    }
  //Declare
    public string BuildConnectionString(ConnectionString connStr) ------> getting error here
    {
        string[] parts = new string[5];
        parts[0] = "Provider=" + connStr.Provider;
        parts[1] = "Data Source=" + connStr.DataSource;
        parts[2] = "User Id=" + connStr.UserId;
        parts[3] = "Password=" + connStr.Password;
        parts[4] = "Initial Catalog=" + connStr.Database;
        return string.Join(";", parts);
    }
    // settings 
    public bool IsValidConnectionForPrinting()
    {
        SetBusy();

        ConnectionString connStr = new ConnectionString();
        connStr.Provider = cboProvider.Text;
        connStr.DataSource = cboDataSource.Text;
        connStr.UserId = txtUserId.Text;
        connStr.Password = txtPassword.Text;
        connStr.Database = cboDatabase.Text;
       //connection string to database 
        string connectionString = BuildConnectionString(connStr);
        OleDbConnection conn = new OleDbConnection(connectionString);
        try
        {
            conn.Open();
            OleDbCommand cmd = conn.CreateCommand;
            cmd.CommandType = CommandType.TableDirect;
            cmd.CommandText = "vw_pr_DL";
            cmd.ExecuteScalar();
            cmd.CommandText = "vw_pr_VR";
            cmd.ExecuteScalar();
            //cmd.CommandText = "vw_pr_VR"
            //cmd.ExecuteScalar()
            conn.Close();
        } 
   //Exception messages
        catch (Exception ex)
        {
            SetFree();
            if (ex.Message.StartsWith("Invalid object name"))
            {
                MessageBox.Show(ex.Message.Replace("Invalid object name", "Table or view not found"), "Connection Test");
            }
            else
            {
                MessageBox.Show(ex.GetBaseException().Message, "Connection Test");
            }
            return false;
        }
        SetFree();
        return true;
    }

// когда пользователь нажимает кнопку тестирования

private void btnConnTest_Click(object sender, EventArgs e)
{

if (IsValidConnectionForPrinting())
    {
         MessageBox.Show("Connection succeeded", "Connection Test");
    }
}
  • Error: User Rate Limit Exceeded

    от Andrew Barber
  • 11

    Error: User Rate Limit Exceeded

    ConnectionStringpublicpublic

    // If it's a class
    public class ConnectionString { ... }
    

  • 33

    Error: User Rate Limit Exceeded

    struct ConnectionString
    {
        public string Provider;
        public string DataSource;
        public string UserId;
        public string Password;
        public string Database;
    }
    

    public struct ConnectionString
    {
        public string Provider;
        public string DataSource;
        public string UserId;
        public string Password;
        public string Database;
    }