Keresés

Új hozzászólás Aktív témák

  • amargo

    addikt

    válasz lakisoft #3002 üzenetére

    static public class DecodeDatabase
    {
    private static SqlConnection m_DecodeConn;
    public static SqlConnection DecodeConn
    {
    get { return DecodeDatabase.m_DecodeConn; }
    }
    public static void InitializeDecodeConnection()
    {
    m_DecodeConn = new SqlConnection();
    try
    {
    m_DecodeConn.ConnectionString = @"Data Source=(local);Initial Catalog=MyDatabase;Integrated Security=True";
    m_DecodeConn.Open();
    }
    catch (Exception e)
    {
    string s = e.Message + Environment.NewLine + m_DecodeConn.ConnectionString;
    m_DecodeConn = null;
    System.Windows.Forms.MessageBox.Show(s, System.Windows.Forms.Application.ProductName, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
    throw e;
    }
    }
    }


    static public class Decode
    {
    static Decode()
    {
    //Inicializálja a dekód adatbázis kapcsolatot
    DecodeDatabase.InitializeDecodeConnection();
    }
    static public string CTGetDecode(string sKey, string sTable, Languages cLanguage)
    {
    using (SqlCommand command = new SqlCommand())
    {
    command.Connection = DecodeDatabase.DecodeConn;
    command.CommandType = CommandType.StoredProcedure;
    command.CommandText = "dbo.GetDecode";
    //command.Parameters.Add(new SqlParameter("@RETURN_VALUE",SqlDbType.Char,60));
    command.Parameters.Add(new SqlParameter("@TableName", sTable));
    command.Parameters.Add(new SqlParameter("@id", sKey));
    object obj = command.ExecuteScalar();
    if (null != obj)
    {
    return obj.ToString();
    }
    else
    {
    throw new ErrKeyNotFound(sKey);
    }
    }
    }
    }

    Így hirtelen, csak bekopiztam.. meg kicsit átírkáltam a neveket.. remélem nem felejtettem ki semmit..

    Ez a lényeg.. alatta csak egy példa lekérdezés
    m_DecodeConn.ConnectionString = @"Data Source=(local);Initial Catalog=MyDatabase;Integrated Security=True";
    m_DecodeConn.Open();

    “The workdays are long and the weekend is short? Make a turn! Bike every day, bike to work too!”

Új hozzászólás Aktív témák