示例#1
0
        public static List<Lang> getLangs()
        {
            SqlConnection conn = new SqlConnection(DBHelper.ConnectionString);
            SqlCommand command = new SqlCommand();
            command.Connection = conn;
            command.CommandText = "getLanguages";
            command.CommandType = System.Data.CommandType.StoredProcedure;

            SqlDataAdapter da = new SqlDataAdapter(command);
            DataSet ds = new DataSet();

            conn.Open();
            da.Fill(ds);
            conn.Close();

            if (ds.Tables[0].Rows.Count == 0)
                return null;

            List<Lang> returnValue = new List<Lang>();
            Lang lang;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                lang = new Lang();
                lang.ID = Convert.ToInt32(dr["ID"]);
                lang.Name = Convert.ToString(dr["langName"]);
                lang.langCode = Convert.ToString(dr["langCode"]);

                returnValue.Add(lang);
            }
            return returnValue;
        }
示例#2
0
        public static Lang getLang(int id)
        {
            SqlConnection conn = new SqlConnection(DBHelper.ConnectionString);
            SqlCommand command = new SqlCommand();
            command.Connection = conn;
            command.CommandText = "getLanguage";
            command.CommandType = System.Data.CommandType.StoredProcedure;

            command.Parameters.Add(new SqlParameter("ID", id));

            SqlDataAdapter da = new SqlDataAdapter(command);
            DataSet ds = new DataSet();

            conn.Open();
            da.Fill(ds);
            conn.Close();

            if (ds.Tables[0].Rows.Count == 0)
                return null;

            Lang lang;
            lang = new Lang();
            DataRow dr = ds.Tables[0].Rows[0];

            lang.ID = Convert.ToInt32(dr["ID"]);
            lang.Name = Convert.ToString(dr["langName"]);
            lang.langCode = Convert.ToString(dr["langCode"]);

            return lang;
        }